Skip to content

[Build] Move the .cfg file generation to a new product. #73845

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions utils/build-presets.ini
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ build-ninja
build-swift-stdlib-unittest-extra

install-llvm
install-static-linux-config
install-swift
install-swiftsyntax

Expand Down Expand Up @@ -394,6 +395,7 @@ skip-test-watchos
skip-test-xros

install-llvm
install-static-linux-config
install-swift
install-llbuild
install-swiftpm
Expand Down Expand Up @@ -618,6 +620,7 @@ sourcekit-lsp
# Failing to build in CI: rdar://78408440
# swift-inspect
install-llvm
install-static-linux-config
install-swift
install-llbuild
install-swiftpm
Expand Down Expand Up @@ -839,6 +842,7 @@ swiftformat

build-ninja
install-llvm
install-static-linux-config
install-swift
install-lldb
install-llbuild
Expand Down Expand Up @@ -993,6 +997,7 @@ host-test

install-prefix=/usr
install-llvm
install-static-linux-config
install-swift
install-swiftsyntax

Expand Down Expand Up @@ -1107,6 +1112,7 @@ xctest
build-subdir=buildbot_linux

install-llvm
install-static-linux-config
install-swift
install-lldb
install-llbuild
Expand Down Expand Up @@ -1178,6 +1184,7 @@ swiftformat
indexstore-db
sourcekit-lsp
install-llvm
install-static-linux-config
install-swift
install-llbuild
install-libicu
Expand Down Expand Up @@ -1220,6 +1227,7 @@ build-subdir=buildbot_incremental_tsan_libdispatch_test
llvm-cmake-options=-DLLVM_INSTALL_UTILS=ON
llvm-install-components=all
install-llvm
install-static-linux-config

libdispatch-cmake-options=-DENABLE_SWIFT=OFF
libdispatch
Expand Down Expand Up @@ -1344,6 +1352,7 @@ extra-cmake-options=
extra-dsymutil-args="--verify-dwarf=none"

install-llvm
install-static-linux-config
install-swift
install-lldb
install-llbuild
Expand Down Expand Up @@ -1631,6 +1640,7 @@ libcxx

# Install swift and libcxx
install-llvm
install-static-linux-config
install-swift
install-swiftsyntax

Expand Down Expand Up @@ -1685,6 +1695,7 @@ swiftsyntax-verify-generated-files
indexstore-db
sourcekit-lsp
install-llvm
install-static-linux-config
install-swift
install-llbuild
install-swiftpm
Expand Down Expand Up @@ -1771,6 +1782,7 @@ llbuild
swiftpm

install-llvm
install-static-linux-config
install-swift
install-llbuild
install-swiftpm
Expand Down Expand Up @@ -2089,6 +2101,7 @@ install-libdispatch
install-libicu
install-libcxx
install-llvm
install-static-linux-config
install-swift
install-llbuild
install-swiftpm
Expand Down Expand Up @@ -2128,6 +2141,7 @@ skip-build-llvm
skip-build-llbuild
skip-build-benchmarks
install-llvm
install-static-linux-config
install-swift
install-swiftsyntax
install-prefix=%(install_toolchain_dir)s/usr
Expand Down Expand Up @@ -2889,6 +2903,7 @@ swiftpm
swift-driver
install-llbuild
install-llvm
install-static-linux-config
install-swift
install-swiftpm
install-swift-driver
Expand Down
3 changes: 3 additions & 0 deletions utils/build_swift/build_swift/driver_arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,9 @@ def create_argument_parser():
option(['--install-swiftpm'], toggle_true('install_swiftpm'),
help='install swiftpm')

option(['--install-static-linux-config'], toggle_true,
help='install static-linux config files for Clang')

option(['--swiftsyntax'], toggle_true('build_swiftsyntax'),
help='build swiftSyntax')

Expand Down
2 changes: 2 additions & 0 deletions utils/build_swift/tests/expected_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
'build_sourcekitlsp': False,
'sourcekitlsp_lint': False,
'install_llvm': False,
'install_static_linux_config': False,
'install_swiftpm': False,
'install_swiftsyntax': False,
'install_swift_driver': False,
Expand Down Expand Up @@ -639,6 +640,7 @@ class BuildScriptImplOption(_BaseOption):
EnableOption('--sourcekit-lsp-lint',
dest='sourcekitlsp_lint'),
EnableOption('--install-llvm', dest='install_llvm'),
EnableOption('--install-static-linux-config', dest='install_static_linux_config'),
EnableOption('--install-swiftsyntax', dest='install_swiftsyntax'),
EnableOption('--swiftsyntax-verify-generated-files',
dest='swiftsyntax_verify_generated_files'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,9 @@ def compute_product_pipelines(self):
builder.add_product(products.LLVM,
is_enabled=True)

builder.add_product(products.StaticSwiftLinuxConfig,
is_enabled=self.args.install_static_linux_config)

builder.add_product(products.LibXML2,
is_enabled=self.args.build_libxml2)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from .playgroundsupport import PlaygroundSupport
from .skstresstester import SKStressTester
from .sourcekitlsp import SourceKitLSP
from .staticswiftlinux import StaticSwiftLinuxConfig
from .swift import Swift
from .swiftdocc import SwiftDocC
from .swiftdoccrender import SwiftDocCRender
Expand Down Expand Up @@ -59,6 +60,7 @@
'MinimalStdlib',
'Ninja',
'PlaygroundSupport',
'StaticSwiftLinuxConfig',
'Swift',
'SwiftFormat',
'SwiftInspect',
Expand Down
37 changes: 0 additions & 37 deletions utils/swift_build_support/swift_build_support/products/llvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,35 +199,6 @@ def copy_embedded_compiler_rt_builtins_from_darwin_host_toolchain(
elif self.args.verbose_build:
print('no file exists at {}'.format(host_lib_path))

def install_static_linux_config(self, arch, bin_dir):
"""Install the .cfg files to set the relevant Clang options for the
fully static Linux SDK's <arch>-swift-linux-musl triple.

Doing it this way means it's easier to modify the defaults without
having to change the compiler driver."""

try:
os.makedirs(bin_dir)
except FileExistsError:
pass

musl_cfg = os.path.join(bin_dir, f'{arch}-swift-linux-musl-clang.cfg')
with open(musl_cfg, "wt") as f:
f.write(f"""
-target {arch}-swift-linux-musl
-rtlib=compiler-rt
-stdlib=libc++
-fuse-ld=lld
-unwindlib=libunwind
-lc++abi
-static
""")
for name in (f'{arch}-swift-linux-musl-clang++.cfg', ):
try:
os.symlink(musl_cfg, os.path.join(bin_dir, name))
except FileExistsError:
pass

def should_build(self, host_target):
"""should_build() -> Bool

Expand Down Expand Up @@ -382,10 +353,6 @@ def build(self, host_target):
host_build_dir = os.path.join(build_root, 'llvm-{}'.format(
host_machine_target))

# Install config files for linux-static
bin_dir = os.path.join(host_build_dir, 'bin')
self.install_static_linux_config(arch, bin_dir)

if self.is_cross_compile_target(host_target):
build_root = os.path.dirname(self.build_dir)
host_machine_target = targets.StdlibDeploymentTarget.host_target().name
Expand Down Expand Up @@ -523,10 +490,6 @@ def install(self, host_target):
clang_dest_dir = '{}{}'.format(host_install_destdir,
self.args.install_prefix)

bin_dir = os.path.join(clang_dest_dir, 'bin')
for arch in self.args.linux_static_archs:
self.install_static_linux_config(arch, bin_dir)

if self.args.llvm_install_components and system() == 'Darwin':
self.copy_embedded_compiler_rt_builtins_from_darwin_host_toolchain(
clang_dest_dir)
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
# swift_build_support/products/staticswiftlinux.py --------------*- python -*-
#
# This source file is part of the Swift.org open source project
#
# Copyright (c) 2014 - 2024 Apple Inc. and the Swift project authors
# Licensed under Apache License v2.0 with Runtime Library Exception
#
# See https://swift.org/LICENSE.txt for license information
# See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
#
# ----------------------------------------------------------------------------

import os

from . import earlyswiftdriver
from . import product


class StaticSwiftLinuxConfig(product.Product):

@classmethod
def is_build_script_impl_product(cls):
"""is_build_script_impl_product -> bool

Whether this product is produced by build-script-impl.
"""
return False

@classmethod
def is_before_build_script_impl_product(cls):
"""is_before_build_script_impl_product -> bool

Whether this product is built before any build-script-impl products.
Such products must be non-build_script_impl products.
Because such products are built ahead of the compiler, they are
built using the host toolchain.
"""
return False

@classmethod
def get_dependencies(cls):
"""Return a list of products that this product depends upon"""
# This is a lie; we don't depend on EarlySwiftDriver, but the
# DAG generator used for --infer doesn't support more than one
# root.
return [earlyswiftdriver.EarlySwiftDriver]

def install_static_linux_config(self, arch, bin_dir):
"""Install the .cfg files to set the relevant Clang options for the
fully static Linux SDK's <arch>-swift-linux-musl triple.

Doing it this way means it's easier to modify the defaults without
having to change the compiler driver."""

try:
os.makedirs(bin_dir)
except FileExistsError:
pass

musl_cfg_name = f'{arch}-swift-linux-musl-clang.cfg'
musl_cfg = os.path.join(bin_dir, musl_cfg_name)
with open(musl_cfg, "wt") as f:
f.write(f"""
-target {arch}-swift-linux-musl
-rtlib=compiler-rt
-stdlib=libc++
-fuse-ld=lld
-unwindlib=libunwind
-lc++abi
-static
""")
for name in (f'{arch}-swift-linux-musl-clang++.cfg', ):
try:
os.symlink(musl_cfg_name, os.path.join(bin_dir, name))
except FileExistsError:
pass

def clean(self, host_target):
"""clean() -> void

Perform the clean, for a non-build-script-impl product.
"""
pass

def should_build(self, host_target):
"""should_build() -> Bool

Whether or not this product should be built with the given arguments.
"""
return False

def build(self, host_target):
"""build() -> void

Perform the build, for a non-build-script-impl product.
"""
pass

def should_test(self, host_target):
"""should_test() -> Bool

Whether or not this product should be tested with the given arguments.
"""
return False

def test(self, host_target):
"""test() -> void

Run the tests, for a non-build-script-impl product.
"""
pass

def should_install(self, host_target):
"""should_install() -> Bool

Whether or not this product should be installed with the given
arguments.
"""
return self.args.install_static_linux_config

def install(self, host_target):
"""install() -> void

Install to the toolchain, for a non-build-script-impl product.
"""
host_install_destdir = self.host_install_destdir(host_target)

clang_dest_dir = '{}{}'.format(host_install_destdir,
self.args.install_prefix)

bin_dir = os.path.join(clang_dest_dir, 'bin')
for arch in self.args.linux_static_archs:
self.install_static_linux_config(arch, bin_dir)
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from . import libcxx
from . import llvm
from . import product
from . import staticswiftlinux
from ..cmake import CMakeOptions


Expand Down Expand Up @@ -265,4 +266,5 @@ def get_dependencies(cls):
return [cmark.CMark,
earlyswiftdriver.EarlySwiftDriver,
llvm.LLVM,
staticswiftlinux.StaticSwiftLinuxConfig,
libcxx.LibCXX]