Skip to content

Commit b94d6d1

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 8c230de commit b94d6d1

File tree

8 files changed

+159
-37
lines changed

8 files changed

+159
-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
@@ -992,6 +996,7 @@ host-test
992996

993997
install-prefix=/usr
994998
install-llvm
999+
install-static-linux-config
9951000
install-swift
9961001
install-swiftsyntax
9971002

@@ -1101,6 +1106,7 @@ xctest
11011106
build-subdir=buildbot_linux
11021107

11031108
install-llvm
1109+
install-static-linux-config
11041110
install-swift
11051111
install-lldb
11061112
install-llbuild
@@ -1170,6 +1176,7 @@ swiftformat
11701176
indexstore-db
11711177
sourcekit-lsp
11721178
install-llvm
1179+
install-static-linux-config
11731180
install-swift
11741181
install-llbuild
11751182
install-libicu
@@ -1212,6 +1219,7 @@ build-subdir=buildbot_incremental_tsan_libdispatch_test
12121219
llvm-cmake-options=-DLLVM_INSTALL_UTILS=ON
12131220
llvm-install-components=all
12141221
install-llvm
1222+
install-static-linux-config
12151223

12161224
libdispatch-cmake-options=-DENABLE_SWIFT=OFF
12171225
libdispatch
@@ -1336,6 +1344,7 @@ extra-cmake-options=
13361344
extra-dsymutil-args="--verify-dwarf=none"
13371345

13381346
install-llvm
1347+
install-static-linux-config
13391348
install-swift
13401349
install-lldb
13411350
install-llbuild
@@ -1601,6 +1610,7 @@ libcxx
16011610

16021611
# Install swift and libcxx
16031612
install-llvm
1613+
install-static-linux-config
16041614
install-swift
16051615
install-swiftsyntax
16061616

@@ -1655,6 +1665,7 @@ swiftsyntax-verify-generated-files
16551665
indexstore-db
16561666
sourcekit-lsp
16571667
install-llvm
1668+
install-static-linux-config
16581669
install-swift
16591670
install-llbuild
16601671
install-swiftpm
@@ -1741,6 +1752,7 @@ llbuild
17411752
swiftpm
17421753

17431754
install-llvm
1755+
install-static-linux-config
17441756
install-swift
17451757
install-llbuild
17461758
install-swiftpm
@@ -2054,6 +2066,7 @@ install-libdispatch
20542066
install-libicu
20552067
install-libcxx
20562068
install-llvm
2069+
install-static-linux-config
20572070
install-swift
20582071
install-llbuild
20592072
install-swiftpm
@@ -2090,6 +2103,7 @@ skip-build-llvm
20902103
skip-build-llbuild
20912104
skip-build-benchmarks
20922105
install-llvm
2106+
install-static-linux-config
20932107
install-swift
20942108
install-swiftsyntax
20952109
install-prefix=%(install_toolchain_dir)s/usr
@@ -2851,6 +2865,7 @@ swiftpm
28512865
swift-driver
28522866
install-llbuild
28532867
install-llvm
2868+
install-static-linux-config
28542869
install-swift
28552870
install-swiftpm
28562871
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
@@ -108,6 +108,7 @@
108108
'build_sourcekitlsp': False,
109109
'sourcekitlsp_lint': False,
110110
'install_llvm': False,
111+
'install_static_linux_config': False,
111112
'install_swiftpm': False,
112113
'install_swiftsyntax': False,
113114
'install_swift_driver': False,
@@ -641,6 +642,7 @@ class BuildScriptImplOption(_BaseOption):
641642
EnableOption('--sourcekit-lsp-lint',
642643
dest='sourcekitlsp_lint'),
643644
EnableOption('--install-llvm', dest='install_llvm'),
645+
EnableOption('--install-static-linux-config', dest='install_static_linux_config'),
644646
EnableOption('--install-swiftsyntax', dest='install_swiftsyntax'),
645647
EnableOption('--swiftsyntax-verify-generated-files',
646648
dest='swiftsyntax_verify_generated_files'),

utils/swift_build_support/swift_build_support/build_script_invocation.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,9 @@ def compute_product_pipelines(self):
626626
builder.add_product(products.LLVM,
627627
is_enabled=True)
628628

629+
builder.add_product(products.StaticSwiftLinuxConfig,
630+
is_enabled=self.args.install_static_linux_config)
631+
629632
builder.add_product(products.LibXML2,
630633
is_enabled=self.args.build_libxml2)
631634

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
@@ -58,6 +59,7 @@
5859
'MinimalStdlib',
5960
'Ninja',
6061
'PlaygroundSupport',
62+
'StaticSwiftLinuxConfig',
6163
'Swift',
6264
'SwiftFormat',
6365
'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
@@ -385,10 +356,6 @@ def build(self, host_target):
385356
host_build_dir = os.path.join(build_root, 'llvm-{}'.format(
386357
host_machine_target))
387358

388-
# Install config files for linux-static
389-
bin_dir = os.path.join(host_build_dir, 'bin')
390-
self.install_static_linux_config(arch, bin_dir)
391-
392359
if self.is_cross_compile_target(host_target):
393360
build_root = os.path.dirname(self.build_dir)
394361
host_machine_target = targets.StdlibDeploymentTarget.host_target().name
@@ -526,10 +493,6 @@ def install(self, host_target):
526493
clang_dest_dir = '{}{}'.format(host_install_destdir,
527494
self.args.install_prefix)
528495

529-
bin_dir = os.path.join(clang_dest_dir, 'bin')
530-
for arch in self.args.linux_static_archs:
531-
self.install_static_linux_config(arch, bin_dir)
532-
533496
if self.args.llvm_install_components and system() == 'Darwin':
534497
self.copy_embedded_compiler_rt_builtins_from_darwin_host_toolchain(
535498
clang_dest_dir)
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
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+
import os
14+
15+
from . import product
16+
from . import earlyswiftdriver
17+
18+
class StaticSwiftLinuxConfig(product.Product):
19+
20+
@classmethod
21+
def is_build_script_impl_product(cls):
22+
"""is_build_script_impl_product -> bool
23+
24+
Whether this product is produced by build-script-impl.
25+
"""
26+
return False
27+
28+
@classmethod
29+
def is_before_build_script_impl_product(cls):
30+
"""is_before_build_script_impl_product -> bool
31+
32+
Whether this product is built before any build-script-impl products.
33+
Such products must be non-build_script_impl products.
34+
Because such products are built ahead of the compiler, they are
35+
built using the host toolchain.
36+
"""
37+
return False
38+
39+
@classmethod
40+
def get_dependencies(cls):
41+
"""Return a list of products that this product depends upon"""
42+
# This is a lie; we don't depend on EarlySwiftDriver, but the
43+
# DAG generator used for --infer doesn't support more than one
44+
# root.
45+
return [earlyswiftdriver.EarlySwiftDriver]
46+
47+
def install_static_linux_config(self, arch, bin_dir):
48+
"""Install the .cfg files to set the relevant Clang options for the
49+
fully static Linux SDK's <arch>-swift-linux-musl triple.
50+
51+
Doing it this way means it's easier to modify the defaults without
52+
having to change the compiler driver."""
53+
54+
try:
55+
os.makedirs(bin_dir)
56+
except FileExistsError:
57+
pass
58+
59+
musl_cfg = os.path.join(bin_dir, f'{arch}-swift-linux-musl-clang.cfg')
60+
with open(musl_cfg, "wt") as f:
61+
f.write(f"""
62+
-target {arch}-swift-linux-musl
63+
-rtlib=compiler-rt
64+
-stdlib=libc++
65+
-fuse-ld=lld
66+
-unwindlib=libunwind
67+
-lc++abi
68+
-static
69+
""")
70+
for name in (f'{arch}-swift-linux-musl-clang++.cfg', ):
71+
try:
72+
os.symlink(musl_cfg, os.path.join(bin_dir, name))
73+
except FileExistsError:
74+
pass
75+
76+
def clean(self, host_target):
77+
"""clean() -> void
78+
79+
Perform the clean, for a non-build-script-impl product.
80+
"""
81+
pass
82+
83+
def should_build(self, host_target):
84+
"""should_build() -> Bool
85+
86+
Whether or not this product should be built with the given arguments.
87+
"""
88+
return False
89+
90+
def build(self, host_target):
91+
"""build() -> void
92+
93+
Perform the build, for a non-build-script-impl product.
94+
"""
95+
pass
96+
97+
def should_test(self, host_target):
98+
"""should_test() -> Bool
99+
100+
Whether or not this product should be tested with the given arguments.
101+
"""
102+
return False
103+
104+
def test(self, host_target):
105+
"""test() -> void
106+
107+
Run the tests, for a non-build-script-impl product.
108+
"""
109+
pass
110+
111+
def should_install(self, host_target):
112+
"""should_install() -> Bool
113+
114+
Whether or not this product should be installed with the given
115+
arguments.
116+
"""
117+
return self.args.install_static_linux_config
118+
119+
def install(self, host_target):
120+
"""install() -> void
121+
122+
Install to the toolchain, for a non-build-script-impl product.
123+
"""
124+
host_install_destdir = self.host_install_destdir(host_target)
125+
126+
clang_dest_dir = '{}{}'.format(host_install_destdir,
127+
self.args.install_prefix)
128+
129+
bin_dir = os.path.join(clang_dest_dir, 'bin')
130+
for arch in self.args.linux_static_archs:
131+
self.install_static_linux_config(arch, bin_dir)
132+

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)