Skip to content

Commit 0e9714a

Browse files
committed
[Build] Move the .cfg file generation to a new product.
We need to move the `.cfg` file generation to a new product so that we can land it in the default toolchain for Xcode. rdar://128612098
1 parent c4b9e32 commit 0e9714a

File tree

7 files changed

+143
-37
lines changed

7 files changed

+143
-37
lines changed

utils/build-presets.ini

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ build-ninja
3737
build-swift-stdlib-unittest-extra
3838

3939
install-llvm
40+
install-static-linux-config
4041
install-swift
4142
install-swiftsyntax
4243

@@ -394,6 +395,7 @@ skip-test-watchos
394395
skip-test-xros
395396

396397
install-llvm
398+
install-static-linux-config
397399
install-swift
398400
install-llbuild
399401
install-swiftpm
@@ -618,6 +620,7 @@ sourcekit-lsp
618620
# Failing to build in CI: rdar://78408440
619621
# swift-inspect
620622
install-llvm
623+
install-static-linux-config
621624
install-swift
622625
install-llbuild
623626
install-swiftpm
@@ -839,6 +842,7 @@ swiftformat
839842

840843
build-ninja
841844
install-llvm
845+
install-static-linux-config
842846
install-swift
843847
install-lldb
844848
install-llbuild
@@ -993,6 +997,7 @@ host-test
993997

994998
install-prefix=/usr
995999
install-llvm
1000+
install-static-linux-config
9961001
install-swift
9971002
install-swiftsyntax
9981003

@@ -1107,6 +1112,7 @@ xctest
11071112
build-subdir=buildbot_linux
11081113

11091114
install-llvm
1115+
install-static-linux-config
11101116
install-swift
11111117
install-lldb
11121118
install-llbuild
@@ -1178,6 +1184,7 @@ swiftformat
11781184
indexstore-db
11791185
sourcekit-lsp
11801186
install-llvm
1187+
install-static-linux-config
11811188
install-swift
11821189
install-llbuild
11831190
install-libicu
@@ -1220,6 +1227,7 @@ build-subdir=buildbot_incremental_tsan_libdispatch_test
12201227
llvm-cmake-options=-DLLVM_INSTALL_UTILS=ON
12211228
llvm-install-components=all
12221229
install-llvm
1230+
install-static-linux-config
12231231

12241232
libdispatch-cmake-options=-DENABLE_SWIFT=OFF
12251233
libdispatch
@@ -1344,6 +1352,7 @@ extra-cmake-options=
13441352
extra-dsymutil-args="--verify-dwarf=none"
13451353

13461354
install-llvm
1355+
install-static-linux-config
13471356
install-swift
13481357
install-lldb
13491358
install-llbuild
@@ -1631,6 +1640,7 @@ libcxx
16311640

16321641
# Install swift and libcxx
16331642
install-llvm
1643+
install-static-linux-config
16341644
install-swift
16351645
install-swiftsyntax
16361646

@@ -1685,6 +1695,7 @@ swiftsyntax-verify-generated-files
16851695
indexstore-db
16861696
sourcekit-lsp
16871697
install-llvm
1698+
install-static-linux-config
16881699
install-swift
16891700
install-llbuild
16901701
install-swiftpm
@@ -1771,6 +1782,7 @@ llbuild
17711782
swiftpm
17721783

17731784
install-llvm
1785+
install-static-linux-config
17741786
install-swift
17751787
install-llbuild
17761788
install-swiftpm
@@ -2089,6 +2101,7 @@ install-libdispatch
20892101
install-libicu
20902102
install-libcxx
20912103
install-llvm
2104+
install-static-linux-config
20922105
install-swift
20932106
install-llbuild
20942107
install-swiftpm
@@ -2128,6 +2141,7 @@ skip-build-llvm
21282141
skip-build-llbuild
21292142
skip-build-benchmarks
21302143
install-llvm
2144+
install-static-linux-config
21312145
install-swift
21322146
install-swiftsyntax
21332147
install-prefix=%(install_toolchain_dir)s/usr
@@ -2889,6 +2903,7 @@ swiftpm
28892903
swift-driver
28902904
install-llbuild
28912905
install-llvm
2906+
install-static-linux-config
28922907
install-swift
28932908
install-swiftpm
28942909
install-swift-driver

utils/build_swift/build_swift/driver_arguments.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,9 @@ def create_argument_parser():
729729
option(['--install-swiftpm'], toggle_true('install_swiftpm'),
730730
help='install swiftpm')
731731

732+
option(['--install-static-linux-config'], toggle_true,
733+
help='install static-linux config files for Clang')
734+
732735
option(['--swiftsyntax'], toggle_true('build_swiftsyntax'),
733736
help='build swiftSyntax')
734737

utils/build_swift/tests/expected_options.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
'build_sourcekitlsp': False,
108108
'sourcekitlsp_lint': False,
109109
'install_llvm': False,
110+
'install_static_linux_config": False,
110111
'install_swiftpm': False,
111112
'install_swiftsyntax': False,
112113
'install_swift_driver': False,
@@ -639,6 +640,7 @@ class BuildScriptImplOption(_BaseOption):
639640
EnableOption('--sourcekit-lsp-lint',
640641
dest='sourcekitlsp_lint'),
641642
EnableOption('--install-llvm', dest='install_llvm'),
643+
EnableOption('--install-static-linux-config', dest='install_static_linux_config'),
642644
EnableOption('--install-swiftsyntax', dest='install_swiftsyntax'),
643645
EnableOption('--swiftsyntax-verify-generated-files',
644646
dest='swiftsyntax_verify_generated_files'),

utils/swift_build_support/swift_build_support/products/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from .playgroundsupport import PlaygroundSupport
2929
from .skstresstester import SKStressTester
3030
from .sourcekitlsp import SourceKitLSP
31+
from .staticswiftlinux import StaticSwiftLinuxConfig
3132
from .swift import Swift
3233
from .swiftdocc import SwiftDocC
3334
from .swiftdoccrender import SwiftDocCRender
@@ -59,6 +60,7 @@
5960
'MinimalStdlib',
6061
'Ninja',
6162
'PlaygroundSupport',
63+
'StaticSwiftLinuxConfig',
6264
'Swift',
6365
'SwiftFormat',
6466
'SwiftInspect',

utils/swift_build_support/swift_build_support/products/llvm.py

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -199,35 +199,6 @@ 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-
231202
def should_build(self, host_target):
232203
"""should_build() -> Bool
233204
@@ -382,10 +353,6 @@ def build(self, host_target):
382353
host_build_dir = os.path.join(build_root, 'llvm-{}'.format(
383354
host_machine_target))
384355

385-
# Install config files for linux-static
386-
bin_dir = os.path.join(host_build_dir, 'bin')
387-
self.install_static_linux_config(arch, bin_dir)
388-
389356
if self.is_cross_compile_target(host_target):
390357
build_root = os.path.dirname(self.build_dir)
391358
host_machine_target = targets.StdlibDeploymentTarget.host_target().name
@@ -523,10 +490,6 @@ def install(self, host_target):
523490
clang_dest_dir = '{}{}'.format(host_install_destdir,
524491
self.args.install_prefix)
525492

526-
bin_dir = os.path.join(clang_dest_dir, 'bin')
527-
for arch in self.args.linux_static_archs:
528-
self.install_static_linux_config(arch, bin_dir)
529-
530493
if self.args.llvm_install_components and system() == 'Darwin':
531494
self.copy_embedded_compiler_rt_builtins_from_darwin_host_toolchain(
532495
clang_dest_dir)
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
# swift_build_support/products/staticswiftlinux.py --------------*- python -*-
2+
#
3+
# This source file is part of the Swift.org open source project
4+
#
5+
# Copyright (c) 2014 - 2024 Apple Inc. and the Swift project authors
6+
# Licensed under Apache License v2.0 with Runtime Library Exception
7+
#
8+
# See https://swift.org/LICENSE.txt for license information
9+
# See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
#
11+
# ----------------------------------------------------------------------------
12+
13+
from . import product
14+
15+
class StaticSwiftLinuxConfig(product.Product):
16+
17+
@classmethod
18+
def is_build_script_impl_product(cls):
19+
"""is_build_script_impl_product -> bool
20+
21+
Whether this product is produced by build-script-impl.
22+
"""
23+
return False
24+
25+
@classmethod
26+
def is_before_build_script_impl_product(cls):
27+
"""is_before_build_script_impl_product -> bool
28+
29+
Whether this product is built before any build-script-impl products.
30+
Such products must be non-build_script_impl products.
31+
Because such products are built ahead of the compiler, they are
32+
built using the host toolchain.
33+
"""
34+
return False
35+
36+
@classmethod
37+
def get_dependencies(cls):
38+
"""Return a list of products that this product depends upon"""
39+
return []
40+
41+
def install_static_linux_config(self, arch, bin_dir):
42+
"""Install the .cfg files to set the relevant Clang options for the
43+
fully static Linux SDK's <arch>-swift-linux-musl triple.
44+
45+
Doing it this way means it's easier to modify the defaults without
46+
having to change the compiler driver."""
47+
48+
try:
49+
os.makedirs(bin_dir)
50+
except FileExistsError:
51+
pass
52+
53+
musl_cfg = os.path.join(bin_dir, f'{arch}-swift-linux-musl-clang.cfg')
54+
with open(musl_cfg, "wt") as f:
55+
f.write(f"""
56+
-target {arch}-swift-linux-musl
57+
-rtlib=compiler-rt
58+
-stdlib=libc++
59+
-fuse-ld=lld
60+
-unwindlib=libunwind
61+
-lc++abi
62+
-static
63+
""")
64+
for name in (f'{arch}-swift-linux-musl-clang++.cfg', ):
65+
try:
66+
os.symlink(musl_cfg, os.path.join(bin_dir, name))
67+
except FileExistsError:
68+
pass
69+
70+
def clean(self, host_target):
71+
"""clean() -> void
72+
73+
Perform the clean, for a non-build-script-impl product.
74+
"""
75+
pass
76+
77+
def build(self, host_target):
78+
"""build() -> void
79+
80+
Perform the build, for a non-build-script-impl product.
81+
"""
82+
pass
83+
84+
def should_test(self, host_target):
85+
"""should_test() -> Bool
86+
87+
Whether or not this product should be tested with the given arguments.
88+
"""
89+
return False
90+
91+
def test(self, host_target):
92+
"""test() -> void
93+
94+
Run the tests, for a non-build-script-impl product.
95+
"""
96+
pass
97+
98+
def should_install(self, host_target):
99+
"""should_install() -> Bool
100+
101+
Whether or not this product should be installed with the given
102+
arguments.
103+
"""
104+
return self.args.install_static_linux_config
105+
106+
def install(self, host_target):
107+
"""install() -> void
108+
109+
Install to the toolchain, for a non-build-script-impl product.
110+
"""
111+
host_install_destdir = self.host_install_destdir(host_target)
112+
113+
clang_dest_dir = '{}{}'.format(host_install_destdir,
114+
self.args.install_prefix)
115+
116+
bin_dir = os.path.join(clang_dest_dir, 'bin')
117+
for arch in self.args.linux_static_archs:
118+
self.install_static_linux_config(arch, bin_dir)
119+

utils/swift_build_support/swift_build_support/products/swift.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from . import earlyswiftdriver
1515
from . import libcxx
1616
from . import llvm
17+
from . import staticswiftlinux
1718
from . import product
1819
from ..cmake import CMakeOptions
1920

@@ -265,4 +266,5 @@ def get_dependencies(cls):
265266
return [cmark.CMark,
266267
earlyswiftdriver.EarlySwiftDriver,
267268
llvm.LLVM,
269+
staticswiftlinux.StaticSwiftLinuxConfig,
268270
libcxx.LibCXX]

0 commit comments

Comments
 (0)