Skip to content

Commit 74f0242

Browse files
committed
Add two version of the Swift flags.
Depending on how a Swift package is configured (`Package.swift`), different flags may be needed. Provide variables with the two forms. Update the documentation to try and explain things and call out the likely error. Move swift-protobuf off a hardcoded override to the new values.
1 parent 7dbf92d commit 74f0242

3 files changed

Lines changed: 17 additions & 28 deletions

File tree

docs/getting-started/new-project-guide/swift_lang.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,12 @@ instead of using the simple base-builder
5858

5959
### build.sh
6060

61-
A `precompile_swift` generates an environment variable `SWIFTFLAGS`
62-
This can then be used in the building command such as `swift build -c release $SWIFTFLAGS`
61+
A `precompile_swift` generates two environment variables `SWIFTFLAGS` and
62+
`SWIFT6_2FLAGS`. These can then be used in the building command such as `swift
63+
build -c release $SWIFTFLAGS`. If your `Package.swift` uses
64+
`// swift-tools-version:6.2` or higher, then use `SWIFT6_2FLAGS` if us using
65+
something lower, you'll want to use `SWIFTFLAGS`. If you get errors like
66+
_undefined symbol '[BINARY\_NAME]\_main'_ then you likely need the 6_2 version.
6367

6468

6569
A usage example from swift-protobuf project is

infra/base-images/base-builder-swift/precompile_swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,26 @@
1717

1818
cp /usr/local/bin/llvm-symbolizer-swift $OUT/llvm-symbolizer
1919

20+
# The flags needed depend on the 'swift-tools-version' in the Package.swift, so
21+
# best we can do it provide two environment variable and let folks use the
22+
# correct one.
23+
2024
export SWIFTFLAGS="-Xswiftc -parse-as-library -Xswiftc -static-stdlib --static-swift-stdlib"
25+
export SWIFT6_2FLAGS="-Xswiftc -static-stdlib --static-swift-stdlib"
2126
if [ "$SANITIZER" = "coverage" ]
2227
then
2328
export SWIFTFLAGS="$SWIFTFLAGS -Xswiftc -profile-generate -Xswiftc -profile-coverage-mapping -Xswiftc -sanitize=fuzzer"
29+
export SWIFT6_2FLAGS="$SWIFT6_2FLAGS -Xswiftc -profile-generate -Xswiftc -profile-coverage-mapping --sanitize=fuzzer"
2430
else
2531
export SWIFTFLAGS="$SWIFTFLAGS -Xswiftc -sanitize=fuzzer,$SANITIZER --sanitize=$SANITIZER"
32+
export SWIFT6_2FLAGS="$SWIFT6_2FLAGS --sanitize=fuzzer --sanitize=$SANITIZER"
2633
for f in $CFLAGS; do
2734
export SWIFTFLAGS="$SWIFTFLAGS -Xcc=$f"
35+
export SWIFT6_2FLAGS="$SWIFT6_2FLAGS -Xcc=$f"
2836
done
2937

3038
for f in $CXXFLAGS; do
3139
export SWIFTFLAGS="$SWIFTFLAGS -Xcxx=$f"
40+
export SWIFT6_2FLAGS="$SWIFT6_2FLAGS -Xcxx=$f"
3241
done
3342
fi

projects/swift-protobuf/build.sh

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,42 +15,18 @@
1515
#
1616
################################################################################
1717

18-
1918
. precompile_swift
2019
cd FuzzTesting
2120

22-
23-
# Normally one would use `$SWIFTFLAGS` (from `precompile_swift``) on this
24-
# invocations, but as we found in
25-
# https://github.com/apple/swift-protobuf/pull/2037, the flags needs depend on
26-
# *both* the Swift Toolchain version *and& the `swift-tools-version` in the
27-
# `Package.swift`.
28-
#
29-
# So, for now, manually recode `precompile_swift` with the flags needed since
30-
# swift-protobuf uses a 6.2+ `swift-tools-version`.
31-
export SWIFTFLAGS="-Xswiftc -static-stdlib --static-swift-stdlib"
32-
if [ "$SANITIZER" = "coverage" ] ; then
33-
export SWIFTFLAGS="$SWIFTFLAGS -Xswiftc -profile-generate -Xswiftc -profile-coverage-mapping --sanitize=fuzzer"
34-
else
35-
export SWIFTFLAGS="$SWIFTFLAGS --sanitize=fuzzer --sanitize=$SANITIZER"
36-
for f in $CFLAGS; do
37-
export SWIFTFLAGS="$SWIFTFLAGS -Xcc=$f"
38-
done
39-
40-
for f in $CXXFLAGS; do
41-
export SWIFTFLAGS="$SWIFTFLAGS -Xcxx=$f"
42-
done
43-
fi
44-
4521
# debug build
46-
swift build -c debug $SWIFTFLAGS
22+
swift build -c debug $SWIFT6_2FLAGS
4723
(
4824
cd .build/debug/
4925
find . -maxdepth 1 -type f -name "Fuzz*" -executable | while read i; do cp $i $OUT/"$i"_debug; done
5026
)
5127

5228
# release build
53-
swift build -c release $SWIFTFLAGS
29+
swift build -c release $SWIFT6_2FLAGS
5430
(
5531
cd .build/release/
5632
find . -maxdepth 1 -type f -name "Fuzz*" -executable | while read i; do cp $i $OUT/"$i"_release; done

0 commit comments

Comments
 (0)