Skip to content

Commit 52d9398

Browse files
authored
Merge pull request swiftlang#34998 from apple/maxd/fix-apple-silicon
CMake: fix build for Apple Silicon hosts When building with `build-script` using these arguments ``` utils/build-script --skip-build-benchmarks --skip-ios --skip-watchos --skip-tvos --swift-darwin-supported-archs "arm64" --sccache --release-debuginfo --test ``` the build fails with ``` ninja: error: 'stdlib/swift-test-stdlib-macosx-x86_64', needed by 'stdlib/CMakeFiles/swift-test-stdlib', missing and no known rule to make it ``` I think that the "Getting Started" guide should avoid hardcoding `x86_64` arguments, and suggest using `$(uname -m)` instead. `SWIFT_PRIMARY_VARIANT_ARCH_default` could also get its value from `CMAKE_HOST_SYSTEM_PROCESSOR` in the root `CMakeLists.txt`. Resolves SR-13943.
2 parents 6a61d11 + 33bc25b commit 52d9398

File tree

5 files changed

+23
-20
lines changed

5 files changed

+23
-20
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,7 @@ elseif("${SWIFT_HOST_VARIANT_SDK}" MATCHES "(OSX|IOS*|TVOS*|WATCHOS*)")
776776
#
777777
# Primary variant is always OSX; even on iOS hosts.
778778
set(SWIFT_PRIMARY_VARIANT_SDK_default "OSX")
779-
set(SWIFT_PRIMARY_VARIANT_ARCH_default "x86_64")
779+
set(SWIFT_PRIMARY_VARIANT_ARCH_default "${CMAKE_HOST_SYSTEM_PROCESSOR}")
780780

781781
endif()
782782

benchmark/README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ The following build options are available:
7474
The following build targets are available:
7575

7676
* `swift-benchmark-macosx-x86_64`
77+
* `swift-benchmark-macosx-arm64`
7778
* `swift-benchmark-iphoneos-arm64e`
7879
* `swift-benchmark-iphoneos-arm64`
7980
* `swift-benchmark-iphoneos-armv7`
@@ -84,7 +85,7 @@ Build steps (with example options):
8485

8586
1. `$ mkdir build; cd build`
8687
2. `$ cmake [path to swift src]/benchmark -G Ninja -DSWIFT_EXEC=[path to built swiftc]`
87-
3. `$ ninja swift-benchmark-macosx-x86_64`
88+
3. `$ ninja swift-benchmark-macosx-$(uname -m)`
8889

8990
Benchmark binaries are placed in `bin`.
9091

@@ -98,7 +99,7 @@ relative to the benchmark binary at the time it was executed
9899
For example, to benchmark against a locally built `swiftc`, including
99100
any standard library changes in that build, you might configure using:
100101

101-
cmake <src>/benchmark -G Ninja -DSWIFT_EXEC=<build>/swift-macosx-x86_64/bin/swiftc
102+
cmake <src>/benchmark -G Ninja -DSWIFT_EXEC=<build>/swift-macosx-$(uname -m)/bin/swiftc
102103
ninja swift-benchmark-iphoneos-arm64
103104

104105
To build against the installed Xcode, simply omit SWIFT_EXEC:
@@ -319,12 +320,12 @@ swift-source$ ./swift/utils/build-script -R -B
319320
````
320321
you can rebuild just the benchmarks:
321322
````
322-
swift-source$ export SWIFT_BUILD_DIR=`pwd`/build/Ninja-ReleaseAssert/swift-macosx-x86_64
323-
swift-source$ ninja -C ${SWIFT_BUILD_DIR} swift-benchmark-macosx-x86_64
323+
swift-source$ export SWIFT_BUILD_DIR=`pwd`/build/Ninja-ReleaseAssert/swift-macosx-$(uname -m)
324+
swift-source$ ninja -C ${SWIFT_BUILD_DIR} swift-benchmark-macosx-$(uname -m)
324325
````
325326

326327
When modifying the testing infrastructure, you should verify that your changes
327328
pass all the tests:
328329
````
329-
swift-source$ ./llvm/utils/lit/lit.py -sv ${SWIFT_BUILD_DIR}/test-macosx-x86_64/benchmark
330+
swift-source$ ./llvm/utils/lit/lit.py -sv ${SWIFT_BUILD_DIR}/test-macosx-$(uname -m)/benchmark
330331
````

docs/DebuggingTheCompiler.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -875,14 +875,14 @@ well as cleanups/modernizations on a code-base. Swift's cmake invocation by
875875
default creates one of these json databases at the root path of the swift host
876876
build, for example on macOS:
877877

878-
$PATH_TO_BUILD/swift-macosx-x86_64/compile_commands.json
878+
$PATH_TO_BUILD/swift-macosx-$(uname -m)/compile_commands.json
879879

880880
Using this file, one invokes `clang-tidy` on a specific file in the codebase
881881
as follows:
882882

883-
clang-tidy -p=$PATH_TO_BUILD/swift-macosx-x86_64/compile_commands.json $FULL_PATH_TO_FILE
883+
clang-tidy -p=$PATH_TO_BUILD/swift-macosx-$(uname -m)/compile_commands.json $FULL_PATH_TO_FILE
884884

885885
One can also use shell regex to visit multiple files in the same directory. Example:
886886

887-
clang-tidy -p=$PATH_TO_BUILD/swift-macosx-x86_64/compile_commands.json $FULL_PATH_TO_DIR/*.cpp
887+
clang-tidy -p=$PATH_TO_BUILD/swift-macosx-$(uname -m)/compile_commands.json $FULL_PATH_TO_DIR/*.cpp
888888

docs/HowToGuides/GettingStarted.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -245,13 +245,13 @@ Phew, that's a lot to digest! Now let's proceed to the actual build itself!
245245
- Via Ninja:
246246
```sh
247247
utils/build-script --skip-build-benchmarks \
248-
--skip-ios --skip-watchos --skip-tvos --swift-darwin-supported-archs "x86_64" \
248+
--skip-ios --skip-watchos --skip-tvos --swift-darwin-supported-archs "$(uname -m)" \
249249
--sccache --release-debuginfo --test
250250
```
251251
- Via Xcode:
252252
```sh
253253
utils/build-script --skip-build-benchmarks \
254-
--skip-ios --skip-watchos --skip-tvos --swift-darwin-supported-archs "x86_64" \
254+
--skip-ios --skip-watchos --skip-tvos --swift-darwin-supported-archs "$(uname -m)" \
255255
--sccache --release-debuginfo --test \
256256
--xcode
257257
```
@@ -350,7 +350,8 @@ git push --set-upstream my-remote my-branch
350350
### First time Xcode setup
351351
352352
If you used `--xcode` earlier, you will see an Xcode project generated under
353-
`../build/Xcode-RelWithDebInfoAssert/swift-macosx-x86_64`. When you open the
353+
`../build/Xcode-RelWithDebInfoAssert/swift-macosx-x86_64` (or
354+
`../build/Xcode-RelWithDebInfoAssert/swift-macosx-arm64` on Apple Silicon Macs). When you open the
354355
project, Xcode might helpfully suggest "Automatically Create Schemes". Most of
355356
those schemes are not required in day-to-day work, so you can instead manually
356357
select the following schemes:
@@ -375,12 +376,12 @@ Now that you have made some changes, you will need to rebuild...
375376
376377
To rebuild the compiler:
377378
```sh
378-
ninja -C ../build/Ninja-RelWithDebInfoAssert/swift-macosx-x86_64 swift-frontend
379+
ninja -C ../build/Ninja-RelWithDebInfoAssert/swift-macosx-$(uname -m) swift-frontend
379380
```
380381
381382
To rebuild everything, including the standard library:
382383
```sh
383-
ninja -C ../build/Ninja-RelWithDebInfoAssert/swift-macosx-x86_64
384+
ninja -C ../build/Ninja-RelWithDebInfoAssert/swift-macosx-$(uname -m)
384385
```
385386
386387
### Incremental builds with Xcode
@@ -396,7 +397,7 @@ build should be much faster than the from-scratch build at the beginning.
396397
Now check if the version string has been updated:
397398
398399
```sh
399-
../build/Ninja-RelWithDebInfoAssert/swift-macosx-x86_64/bin/swift-frontend --version
400+
../build/Ninja-RelWithDebInfoAssert/swift-macosx-$(uname -m)/bin/swift-frontend --version
400401
```
401402
402403
This should print your updated version string.
@@ -439,22 +440,22 @@ There are two main ways to run tests:
439440
```sh
440441
# Rebuild all test dependencies and run all tests under test/.
441442
utils/run-test --lit ../llvm-project/llvm/utils/lit/lit.py \
442-
../build/Ninja-RelWithDebInfoAssert/swift-macosx-x86_64/test-macosx-x86_64
443+
../build/Ninja-RelWithDebInfoAssert/swift-macosx-$(uname -m)/test-macosx-$(uname -m)
443444
444445
# Rebuild all test dependencies and run tests containing "MyTest".
445446
utils/run-test --lit ../llvm-project/llvm/utils/lit/lit.py \
446-
../build/Ninja-RelWithDebInfoAssert/swift-macosx-x86_64/test-macosx-x86_64 \
447+
../build/Ninja-RelWithDebInfoAssert/swift-macosx-$(uname -m)/test-macosx-$(uname -m) \
447448
--filter="MyTest"
448449
```
449450
2. `lit.py`: lit doesn't know anything about dependencies. It just runs tests.
450451
```sh
451452
# Run all tests under test/.
452453
../llvm-project/llvm/utils/lit/lit.py -s -vv \
453-
../build/Ninja-RelWithDebInfoAssert/swift-macosx-x86_64/test-macosx-x86_64
454+
../build/Ninja-RelWithDebInfoAssert/swift-macosx-$(uname -m)/test-macosx-$(uname -m)
454455
455456
# Run tests containing "MyTest"
456457
../llvm-project/llvm/utils/lit/lit.py -s -vv \
457-
../build/Ninja-RelWithDebInfoAssert/swift-macosx-x86_64/test-macosx-x86_64 \
458+
../build/Ninja-RelWithDebInfoAssert/swift-macosx-$(uname -m)/test-macosx-$(uname -m) \
458459
--filter="MyTest"
459460
```
460461
The `-s` and `-vv` flags print a progress bar and the executed commands

utils/coverage/coverage-generate-data

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import logging
1414
import multiprocessing
1515
import os
1616
import pipes
17+
import platform
1718
import subprocess
1819
import sys
1920
import timeit
@@ -100,7 +101,7 @@ def dump_coverage_data(merged_file):
100101
"""Dump coverage data of file at path `merged_file` using llvm-cov"""
101102
try:
102103
swift = os.path.join(global_build_subdir,
103-
'swift-macosx-x86_64/bin/swift')
104+
'swift-macosx-{}/bin/swift'.format(platform.machine()))
104105
coverage_log = os.path.join(os.path.dirname(merged_file),
105106
'coverage.log')
106107
testname = os.path.basename(os.path.dirname(merged_file))

0 commit comments

Comments
 (0)