Skip to content

[bootstrap] Add a --skip-cmake-bootstrap flag to use a prebuilt swift-build #3000

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
Nov 2, 2020
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
17 changes: 10 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,27 @@ endif()
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

option(BUILD_SHARED_LIBS "Build shared libraries by default" YES)
option(FIND_PM_DEPS "Search for all external Package Manager dependencies" YES)

string(COMPARE EQUAL ${CMAKE_SYSTEM_NAME} Windows CMAKE_INSTALL_DEFAULT)
option(USE_CMAKE_INSTALL
"Install build products using cmake's install() instead of the bootstrap script's install()"
${CMAKE_INSTALL_DEFAULT})

find_package(TSC CONFIG REQUIRED)
if(FIND_PM_DEPS)
find_package(TSC CONFIG REQUIRED)

find_package(LLBuild CONFIG)
if(NOT LLBuild_FOUND)
find_package(LLBuild REQUIRED)
find_package(LLBuild CONFIG)
if(NOT LLBuild_FOUND)
find_package(LLBuild REQUIRED)
endif()

find_package(ArgumentParser CONFIG REQUIRED)
find_package(SwiftDriver CONFIG REQUIRED)
endif()

find_package(dispatch QUIET)
find_package(Foundation QUIET)

find_package(ArgumentParser CONFIG REQUIRED)
find_package(SwiftDriver CONFIG REQUIRED)

add_subdirectory(Sources)
add_subdirectory(cmake/modules)
82 changes: 53 additions & 29 deletions Utilities/bootstrap
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ def add_build_args(parser):
"--release",
action="store_true",
help="enables building SwiftPM in release mode")
parser.add_argument(
"--skip-cmake-bootstrap",
action="store_true",
help="build with prebuilt package manager in toolchain if it exists")
parser.add_argument(
"--libswiftpm-install-dir",
metavar='PATH',
Expand Down Expand Up @@ -198,6 +202,8 @@ def parse_build_args(args):
args.bootstrap_dir = os.path.join(args.target_dir, "bootstrap")
args.conf = 'release' if args.release else 'debug'
args.bin_dir = os.path.join(args.target_dir, args.conf)
args.bootstrap = not args.skip_cmake_bootstrap or \
not os.path.exists(os.path.join(os.path.split(args.swiftc_path)[0], "swift-build"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a refinement, would it make sense to emit an error if --skip-cmake-bootstrap is true but there's no swift-build, rather than going through with the bootstrap?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I figured it's better to then try the bootstrap build as a backup, but could go either way. If you prefer, I can add a warning or error out in my next pull to cross-compile SPM for Android.


def parse_test_args(args):
"""Parses and cleans arguments necessary for the test action."""
Expand Down Expand Up @@ -296,10 +302,12 @@ def build(args):
if not args.llbuild_build_dir:
build_llbuild(args)

build_tsc(args)
build_yams(args)
build_swift_argument_parser(args)
build_swift_driver(args)
if args.bootstrap:
build_tsc(args)
build_yams(args)
build_swift_argument_parser(args)
build_swift_driver(args)

build_swiftpm_with_cmake(args)
build_swiftpm_with_swiftpm(args,integrated_swift_driver=False)

Expand Down Expand Up @@ -433,7 +441,7 @@ def install_binary(args, binary, dest_dir):
# Build functions
# -----------------------------------------------------------

def build_with_cmake(args, cmake_args, source_path, build_dir):
def build_with_cmake(args, cmake_args, source_path, build_dir, targets=[]):
"""Runs CMake if needed, then builds with Ninja."""
cache_path = os.path.join(build_dir, "CMakeCache.txt")
if args.reconfigure or not os.path.isfile(cache_path) or not args.swiftc_path in open(cache_path).read():
Expand Down Expand Up @@ -461,6 +469,8 @@ def build_with_cmake(args, cmake_args, source_path, build_dir):
if args.verbose:
ninja_cmd.append("-v")

ninja_cmd += targets

call(ninja_cmd, cwd=build_dir, verbose=args.verbose)

def build_llbuild(args):
Expand Down Expand Up @@ -558,19 +568,25 @@ def build_swiftpm_with_cmake(args):
"""Builds SwiftPM using CMake."""
note("Building SwiftPM (with CMake)")

cmake_flags = [
get_llbuild_cmake_arg(args),
"-DTSC_DIR=" + os.path.join(args.tsc_build_dir, "cmake/modules"),
"-DYams_DIR=" + os.path.join(args.yams_build_dir, "cmake/modules"),
"-DArgumentParser_DIR=" + os.path.join(args.swift_argument_parser_build_dir, "cmake/modules"),
"-DSwiftDriver_DIR=" + os.path.join(args.swift_driver_build_dir, "cmake/modules"),
]
if args.bootstrap:
cmake_flags = [
get_llbuild_cmake_arg(args),
"-DTSC_DIR=" + os.path.join(args.tsc_build_dir, "cmake/modules"),
"-DYams_DIR=" + os.path.join(args.yams_build_dir, "cmake/modules"),
"-DArgumentParser_DIR=" + os.path.join(args.swift_argument_parser_build_dir, "cmake/modules"),
"-DSwiftDriver_DIR=" + os.path.join(args.swift_driver_build_dir, "cmake/modules"),
"-DFIND_PM_DEPS:BOOL=YES",
]
else:
cmake_flags = [ "-DFIND_PM_DEPS:BOOL=NO" ]

if platform.system() == 'Darwin':
cmake_flags.append("-DCMAKE_C_FLAGS=-target %s%s" % (get_build_target(args), g_macos_deployment_target))
cmake_flags.append("-DCMAKE_OSX_DEPLOYMENT_TARGET=%s" % g_macos_deployment_target)

build_with_cmake(args, cmake_flags, args.project_root, args.bootstrap_dir)
targets = [] if args.bootstrap else ["PD4", "PD4_2"]

build_with_cmake(args, cmake_flags, args.project_root, args.bootstrap_dir, targets)

if args.llbuild_link_framework:
add_rpath_for_cmake_build(args, args.llbuild_build_dir)
Expand All @@ -582,15 +598,22 @@ def build_swiftpm_with_cmake(args):

def build_swiftpm_with_swiftpm(args, integrated_swift_driver):
"""Builds SwiftPM using the version of SwiftPM built with CMake."""
note("Building SwiftPM (with swift-build)")

swiftpm_args = [
"SWIFT_EXEC=" + args.swiftc_path,
"SWIFT_DRIVER_SWIFT_EXEC=" + args.swiftc_path,
"SWIFTPM_PD_LIBS=" + os.path.join(args.bootstrap_dir, "pm"),
os.path.join(args.bootstrap_dir, "bin/swift-build"),
"--disable-sandbox",
]

if args.bootstrap:
note("Building SwiftPM (with a freshly built swift-build)")
swiftpm_args.append("SWIFTPM_PD_LIBS=" + os.path.join(args.bootstrap_dir, "pm"))
swiftpm_args.append(os.path.join(args.bootstrap_dir, "bin/swift-build"))
else:
note("Building SwiftPM (with a prebuilt swift-build)")
swiftpm_args.append(os.path.join(os.path.split(args.swiftc_path)[0], "swift-build"))

swiftpm_args.append("--disable-sandbox")

if integrated_swift_driver:
swiftpm_args.append("--use-integrated-swift-driver")

Expand Down Expand Up @@ -660,19 +683,20 @@ def get_swiftpm_env_cmd(args):
env_cmd.append("SWIFTCI_USE_LOCAL_DEPS=1")
env_cmd.append("SWIFTPM_MACOS_DEPLOYMENT_TARGET=%s" % g_macos_deployment_target)

libs_joined = ":".join([
os.path.join(args.bootstrap_dir, "lib"),
os.path.join(args.tsc_build_dir, "lib"),
os.path.join(args.llbuild_build_dir, "lib"),
os.path.join(args.yams_build_dir, "lib"),
os.path.join(args.swift_argument_parser_build_dir, "lib"),
os.path.join(args.swift_driver_build_dir, "lib"),
] + args.target_info["paths"]["runtimeLibraryPaths"])
if args.bootstrap:
libs_joined = ":".join([
os.path.join(args.bootstrap_dir, "lib"),
os.path.join(args.tsc_build_dir, "lib"),
os.path.join(args.llbuild_build_dir, "lib"),
os.path.join(args.yams_build_dir, "lib"),
os.path.join(args.swift_argument_parser_build_dir, "lib"),
os.path.join(args.swift_driver_build_dir, "lib"),
] + args.target_info["paths"]["runtimeLibraryPaths"])

if platform.system() == 'Darwin':
env_cmd.append("DYLD_LIBRARY_PATH=%s" % libs_joined)
else:
env_cmd.append("LD_LIBRARY_PATH=%s" % libs_joined)
if platform.system() == 'Darwin':
env_cmd.append("DYLD_LIBRARY_PATH=%s" % libs_joined)
else:
env_cmd.append("LD_LIBRARY_PATH=%s" % libs_joined)

return env_cmd

Expand Down