Skip to content

Commit 925f715

Browse files
authored
Merge pull request #73863 from al45tair/eng/PR-128612098-6.0
[Build] Move the `.cfg` file generation to a new product.
2 parents a3a65bf + 3441323 commit 925f715

File tree

8 files changed

+160
-37
lines changed

8 files changed

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

utils/swift_build_support/swift_build_support/products/swift.py

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

2021

@@ -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)