Skip to content

Commit 3627507

Browse files
committed
[Build] Further static Linux SDK support changes.
Fix some indentation issues. Change `build-script-impl` to make `build-linux-static` a positive argument. Fix documentation for `--linux-archs` and `--linux-static-archs` (the options are comma separated for `build-script`, but semicolon separated for `build-script-impl`). Set the default for `linux-static-archs` to `x86_64, aarch64` so that we install the expected content in the toolchain. Add missing default for `test_linux_static`. Make sure to pass down `--skip-build-linux` and `--build-linux-static`. Factor out config file generation and call it from the install step in `llvm.py` as well as from the build step. rdar://123503470
1 parent bac73d0 commit 3627507

File tree

6 files changed

+52
-33
lines changed

6 files changed

+52
-33
lines changed

stdlib/cmake/modules/AddSwiftStdlib.cmake

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2432,9 +2432,9 @@ function(add_swift_target_library name)
24322432
if (SWIFTLIB_IS_STDLIB AND SWIFTLIB_STATIC)
24332433
# Add dependencies on the (not-yet-created) custom lipo target.
24342434
foreach(DEP ${SWIFTLIB_LINK_LIBRARIES})
2435-
if (NOT "${DEP}" MATCHES "^icucore($|-.*)$" AND
2436-
NOT "${DEP}" MATCHES "^dispatch($|-.*)$" AND
2437-
NOT "${DEP}" MATCHES "^BlocksRuntime($|-.*)$")
2435+
if (NOT "${DEP}" MATCHES "^icucore($|-.*)$" AND
2436+
NOT "${DEP}" MATCHES "^dispatch($|-.*)$" AND
2437+
NOT "${DEP}" MATCHES "^BlocksRuntime($|-.*)$")
24382438
add_dependencies("${VARIANT_NAME}-static"
24392439
"${DEP}-${SWIFT_SDK_${sdk}_LIB_SUBDIR}-static")
24402440
endif()

utils/build-script-impl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ KNOWN_SETTINGS=(
9797
musl-path "/usr/local/musl" "The path to the Musl headers and libraries"
9898
linux-archs "" "The Linux target architecture(s)"
9999
linux-static-archs "" "The fully static Linux target architecture(s)"
100+
build-linux-static "" "set to build Swift stdlibs for statically linked Linux"
100101

101102
## Darwin Options
102103
darwin-crash-reporter-client "" "whether to enable CrashReporter integration, default is 1 on Darwin platforms, 0 otherwise"
@@ -136,7 +137,6 @@ KNOWN_SETTINGS=(
136137
skip-build "" "set to configure as usual while skipping the build step"
137138
skip-build-android "" "set to skip building Swift stdlibs for Android"
138139
skip-build-linux "" "set to skip building Swift stdlibs for Linux"
139-
skip-build-linux-static "" "set to skip building Swift stdlibs for statically linked Linux"
140140
skip-build-wasm "" "set to skip building Swift stdlibs for WebAssembly"
141141
skip-build-benchmarks "" "set to skip building Swift Benchmark Suite"
142142
skip-build-clang-tools-extra "" "set to skip building clang-tools-extra as part of llvm"
@@ -1733,7 +1733,7 @@ for host in "${ALL_HOSTS[@]}"; do
17331733
)
17341734
fi
17351735

1736-
if [[ ! "${SKIP_BUILD_LINUX_STATIC}" ]]; then
1736+
if [[ "${BUILD_LINUX_STATIC}" ]]; then
17371737
cmake_options=(
17381738
"${cmake_options[@]}"
17391739
-DSWIFT_MUSL_PATH:STRING="${MUSL_PATH}"

utils/build_swift/build_swift/driver_arguments.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1397,7 +1397,7 @@ def create_argument_parser():
13971397
option('--linux-archs', store,
13981398
type=argparse.ShellSplitType(),
13991399
default=None,
1400-
help='Semicolon-separated list of architectures to use when '
1400+
help='Comma-separated list of architectures to use when '
14011401
'building for Linux.')
14021402

14031403
# -------------------------------------------------------------------------
@@ -1409,8 +1409,8 @@ def create_argument_parser():
14091409

14101410
option('--linux-static-archs', store,
14111411
type=argparse.ShellSplitType(),
1412-
default=None,
1413-
help='Semicolon-separated list of architectures to use when '
1412+
default=['x86_64', 'aarch64'],
1413+
help='Comma-separated list of architectures to use when '
14141414
'building for fully static Linux.')
14151415

14161416
# -------------------------------------------------------------------------

utils/build_swift/tests/expected_options.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@
238238
'maccatalyst': False,
239239
'maccatalyst_ios_tests': False,
240240
'musl_path': '/usr/local/musl',
241-
'linux_static_archs': None,
241+
'linux_static_archs': ['x86_64', 'aarch64'],
242242
'native_clang_tools_path': None,
243243
'native_llvm_tools_path': None,
244244
'native_swift_tools_path': None,
@@ -285,6 +285,7 @@
285285
'test_ios_host': False,
286286
'test_ios_simulator': False,
287287
'test_linux': False,
288+
'test_linux_static': False,
288289
'test_optimize_for_size': None,
289290
'test_optimize_none_with_implicit_dynamic': None,
290291
'test_optimized': None,

utils/swift_build_support/swift_build_support/build_script_invocation.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,11 @@ def convert_to_impl_arguments(self):
533533
"--linux-archs=%s" % ';'.join(args.linux_archs)
534534
]
535535

536+
if not args.build_linux:
537+
impl_args += ["--skip-build-linux"]
538+
if args.build_linux_static:
539+
impl_args += ["--build-linux-static"]
540+
536541
# Compute the set of host-specific variables, which we pass through to
537542
# the build script via environment variables.
538543
host_specific_variables = self.compute_host_specific_variables()

utils/swift_build_support/swift_build_support/products/llvm.py

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,35 @@ def copy_embedded_compiler_rt_builtins_from_darwin_host_toolchain(
199199
elif self.args.verbose_build:
200200
print('no file exists at {}'.format(host_lib_path))
201201

202+
def install_static_linux_config(self, arch, bin_dir):
203+
"""Install the .cfg files to set the relevant Clang options for the
204+
fully static Linux SDK's <arch>-swift-linux-musl triple.
205+
206+
Doing it this way means it's easier to modify the defaults without
207+
having to change the compiler driver."""
208+
209+
try:
210+
os.makedirs(bin_dir)
211+
except FileExistsError:
212+
pass
213+
214+
musl_cfg = os.path.join(bin_dir, f'{arch}-swift-linux-musl-clang.cfg')
215+
with open(musl_cfg, "wt") as f:
216+
f.write(f"""
217+
-target {arch}-swift-linux-musl
218+
-rtlib=compiler-rt
219+
-stdlib=libc++
220+
-fuse-ld=lld
221+
-unwindlib=libunwind
222+
-lc++abi
223+
-static
224+
""")
225+
for name in (f'{arch}-swift-linux-musl-clang++.cfg', ):
226+
try:
227+
os.symlink(musl_cfg, os.path.join(bin_dir, name))
228+
except FileExistsError:
229+
pass
230+
202231
def should_build(self, host_target):
203232
"""should_build() -> Bool
204233
@@ -354,28 +383,7 @@ def build(self, host_target):
354383

355384
# Install config files for linux-static
356385
bin_dir = os.path.join(host_build_dir, 'bin')
357-
try:
358-
os.makedirs(bin_dir)
359-
except FileExistsError:
360-
pass
361-
362-
musl_cfg = os.path.join(bin_dir, f'{arch}-swift-linux-musl-clang.cfg')
363-
with open(musl_cfg, "wt") as f:
364-
f.write(f"""
365-
-target {arch}-swift-linux-musl
366-
-rtlib=compiler-rt
367-
-stdlib=libc++
368-
-fuse-ld=lld
369-
-unwindlib=libunwind
370-
-lc++abi
371-
-funwind-tables
372-
-fasynchronous-unwind-tables
373-
""")
374-
for name in (f'{arch}-swift-linux-musl-clang++.cfg', ):
375-
try:
376-
os.symlink(musl_cfg, os.path.join(host_build_dir, 'bin', name))
377-
except FileExistsError:
378-
pass
386+
self.install_static_linux_config(arch, bin_dir)
379387

380388
if self.is_cross_compile_target(host_target):
381389
build_root = os.path.dirname(self.build_dir)
@@ -511,8 +519,13 @@ def install(self, host_target):
511519

512520
self.install_with_cmake(install_targets, host_install_destdir)
513521

522+
clang_dest_dir = '{}{}'.format(host_install_destdir,
523+
self.args.install_prefix)
524+
525+
bin_dir = os.path.join(clang_dest_dir, 'bin')
526+
for arch in self.args.linux_static_archs:
527+
self.install_static_linux_config(arch, bin_dir)
528+
514529
if self.args.llvm_install_components and system() == 'Darwin':
515-
clang_dest_dir = '{}{}'.format(host_install_destdir,
516-
self.args.install_prefix)
517530
self.copy_embedded_compiler_rt_builtins_from_darwin_host_toolchain(
518531
clang_dest_dir)

0 commit comments

Comments
 (0)