Skip to content

Commit 60c7a44

Browse files
committed
Bootstrap script needs to build PackageDescription and PackagePlugin libraries universal when cross-compiling. We do this by installing the one built by SwiftPM instead of, as previously, the one built by CMake. This change depends on the one to unify PackageDescription 4.0 and 4.2 into one library, so that it can be built by SwiftPM.
This also cleans up the bootstrap script by consolidating some of the functionality for copying a library. rdar://75186958
1 parent 2d64d68 commit 60c7a44

File tree

1 file changed

+36
-50
lines changed

1 file changed

+36
-50
lines changed

Utilities/bootstrap

Lines changed: 36 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,11 @@ from helpers import note, error, symlink_force, mkdir_p, call, call_output
2727

2828
g_macos_deployment_target = '10.15'
2929

30+
g_shared_lib_prefix = "lib"
3031
if platform.system() == 'Darwin':
31-
g_shared_lib_ext = ".dylib"
32+
g_shared_lib_suffix = ".dylib"
3233
else:
33-
g_shared_lib_ext = ".so"
34+
g_shared_lib_suffix = ".so"
3435

3536
def main():
3637
parser = argparse.ArgumentParser(description="""
@@ -366,7 +367,7 @@ def install(args):
366367
"PackageGraph", "SPMBuildCore", "Build",
367368
"Xcodeproj", "Workspace"
368369
]
369-
install_libswiftpm_dylib(args, "SwiftPM", args.libswiftpm_install_dir, libswiftpm_modules)
370+
install_dylib(args, "SwiftPM", args.libswiftpm_install_dir, libswiftpm_modules)
370371

371372
# Install libSwiftPMDataModel if an install directory was provided.
372373
if args.libswiftpmdatamodel_install_dir:
@@ -377,67 +378,49 @@ def install(args):
377378
"PackageGraph", "SPMBuildCore",
378379
"Xcodeproj", "Workspace"
379380
]
380-
install_libswiftpm_dylib(args, "SwiftPMDataModel", args.libswiftpmdatamodel_install_dir, libswiftpmdatamodel_modules)
381+
install_dylib(args, "SwiftPMDataModel", args.libswiftpmdatamodel_install_dir, libswiftpmdatamodel_modules)
381382

383+
# Installs the SwiftPM tools and runtime support libraries.
382384
def install_swiftpm(prefix, args):
383-
# Install swiftpm binary and create tool symlinks.
385+
# Install the swift-package tool and create symlinks to it.
384386
cli_tool_dest = os.path.join(prefix, "bin")
385387
install_binary(args, "swift-package", cli_tool_dest)
386388
for tool in ["swift-build", "swift-test", "swift-run", "swift-package-collection"]:
387389
src = "swift-package"
388390
dest = os.path.join(cli_tool_dest, tool)
389391
note("Creating tool symlink from %s to %s" % (src, dest))
390392
symlink_force(src, dest)
391-
393+
394+
# On Darwin, also install the swiftpm-xctest-helper tool.
392395
if platform.system() == 'Darwin':
393396
dest = os.path.join(prefix, "libexec", "swift", "pm")
394397
install_binary(args, "swiftpm-xctest-helper", dest)
395398

396-
# Install PackageDescription runtime libraries.
397-
runtime_lib_dest = os.path.join(prefix, "lib", "swift", "pm")
398-
runtime_lib_src = os.path.join(args.bootstrap_dir, "pm")
399-
400-
files_to_install = ["libPackageDescription" + g_shared_lib_ext]
401-
if platform.system() == 'Darwin':
402-
files_to_install.append("PackageDescription.swiftinterface")
403-
else:
404-
files_to_install.append("PackageDescription.swiftmodule")
405-
files_to_install.append("PackageDescription.swiftdoc")
406-
407-
for file in files_to_install:
408-
src = os.path.join(runtime_lib_src, "ManifestAPI", file)
409-
dest = os.path.join(runtime_lib_dest, "ManifestAPI", file)
410-
mkdir_p(os.path.dirname(dest))
411-
412-
note("Installing %s to %s" % (src, dest))
413-
414-
file_util.copy_file(src, dest, update=1)
415-
416-
files_to_install = ["libPackagePlugin" + g_shared_lib_ext]
417-
if platform.system() == 'Darwin':
418-
files_to_install.append("PackagePlugin.swiftinterface")
419-
else:
420-
files_to_install.append("PackagePlugin.swiftmodule")
421-
files_to_install.append("PackagePlugin.swiftdoc")
422-
423-
for file in files_to_install:
424-
src = os.path.join(runtime_lib_src, "PluginAPI", file)
425-
dest = os.path.join(runtime_lib_dest, "PluginAPI", file)
426-
mkdir_p(os.path.dirname(dest))
427-
428-
note("Installing %s to %s" % (src, dest))
429-
430-
file_util.copy_file(src, dest, update=1)
399+
# Install the PackageDescription library and associated modules.
400+
dest = os.path.join(prefix, "lib", "swift", "pm", "ManifestAPI")
401+
install_dylib(args, "PackageDescription", dest, ["PackageDescription"])
402+
403+
# Install the PackagePlugin library and associated modules.
404+
dest = os.path.join(prefix, "lib", "swift", "pm", "PluginAPI")
405+
install_dylib(args, "PackagePlugin", dest, ["PackagePlugin"])
431406

432407

433-
def install_libswiftpm_dylib(args, library_name, install_dir, module_names):
434-
# FIXME: Don't hardcode the prefix and suffix.
435-
install_binary(args, "lib" + library_name + ".dylib", install_dir)
408+
# Helper function that installs a dynamic library and a set of modules to a particular directory.
409+
def install_dylib(args, library_name, install_dir, module_names):
410+
# Install the dynamic library itself.
411+
install_binary(args, g_shared_lib_prefix + library_name + g_shared_lib_suffix, install_dir)
436412

437-
# Install the swiftmodule and swiftdoc files.
413+
# Install the swiftmodule/swiftinterface and swiftdoc files for all the modules.
438414
for module in module_names:
439-
install_binary(args, module + ".swiftmodule", install_dir)
440-
if not args.cross_compile_hosts: # When compiling for multiple arches, swiftdoc is part of the swiftmodule directory
415+
# If we're cross-compiling, we expect the .swiftmodule to be a directory that contains everything.
416+
if args.cross_compile_hosts:
417+
install_binary(args, module + ".swiftmodule", install_dir)
418+
else:
419+
# Otherwise we have either a .swiftinterface or a .swiftmodule, plus a .swiftdoc.
420+
if os.path.exists(os.path.join(args.bin_dir, module + ".swiftinterface")):
421+
install_binary(args, module + ".swiftinterface", install_dir)
422+
else:
423+
install_binary(args, module + ".swiftmodule", install_dir)
441424
install_binary(args, module + ".swiftdoc", install_dir)
442425

443426
# Install the C headers.
@@ -446,17 +429,18 @@ def install_libswiftpm_dylib(args, library_name, install_dir, module_names):
446429
dir_util.copy_tree(tscclibc_include_dir, tscclibc_include_dir_dest)
447430

448431

432+
# Helper function that installs a single built artifact to a particular directory. The source may be either a file or a directory.
449433
def install_binary(args, binary, dest_dir):
450434
src = os.path.join(args.bin_dir, binary)
451435
dest = os.path.join(dest_dir, binary)
452436

453437
note("Installing %s to %s" % (src, dest))
454438

455439
mkdir_p(os.path.dirname(dest))
456-
if os.path.isdir(src) and args.cross_compile_hosts: # Handle swiftmodule directories if compiling for multiple arches.
457-
dir_util.copy_tree(src, dest)
440+
if os.path.isdir(src):
441+
dir_util.copy_tree(src, dest, update=1, verbose=1)
458442
else:
459-
file_util.copy_file(src, dest, update=1)
443+
file_util.copy_file(src, dest, update=1, verbose=1)
460444

461445
# -----------------------------------------------------------
462446
# Build functions
@@ -651,6 +635,8 @@ def build_swiftpm_with_swiftpm(args, integrated_swift_driver):
651635
if integrated_swift_driver:
652636
swiftpm_args.append("--use-integrated-swift-driver")
653637

638+
swiftpm_args.append("--enable-parseable-module-interfaces")
639+
654640
call_swiftpm(args, swiftpm_args)
655641

656642
# Setup symlinks that'll allow using swiftpm from the build directory.

0 commit comments

Comments
 (0)