Skip to content

Commit c3b1c8c

Browse files
committed
Bootstrap script needs to build PackageDescription (both 4 and 4_2) and PackagePlugin libraries universal when cross-compiling.
rdar://75186958
1 parent 2bb3e5e commit c3b1c8c

File tree

2 files changed

+36
-38
lines changed

2 files changed

+36
-38
lines changed

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ let package = Package(
121121
/** Package Definition API */
122122
name: "PackageDescription",
123123
swiftSettings: [
124-
.define("PACKAGE_DESCRIPTION_4_2"),
124+
.define("PACKAGE_DESCRIPTION_\(ProcessInfo.processInfo.environment["SWIFTPM_PACKAGE_DESCRIPTION_VERSION"] ?? "4_2")"),
125125
]),
126126

127127
.target(

Utilities/bootstrap

Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ def parse_build_args(args):
202202
args.target_dir = os.path.join(args.build_dir, get_build_target(args))
203203
args.bootstrap_dir = os.path.join(args.target_dir, "bootstrap")
204204
args.conf = 'release' if args.release else 'debug'
205+
args.pkgdesc_version = "4_2"
205206
args.bin_dir = os.path.join(args.target_dir, args.conf)
206207
args.bootstrap = not args.skip_cmake_bootstrap or \
207208
not os.path.exists(os.path.join(os.path.split(args.swiftc_path)[0], "swift-build"))
@@ -389,42 +390,16 @@ def install_swiftpm(prefix, args):
389390
dest = os.path.join(prefix, "libexec", "swift", "pm")
390391
install_binary(args, "swiftpm-xctest-helper", dest)
391392

392-
# Install PackageDescription runtime libraries.
393-
runtime_lib_dest = os.path.join(prefix, "lib", "swift", "pm")
394-
runtime_lib_src = os.path.join(args.bootstrap_dir, "pm")
395-
396-
for runtime in ["4", "4_2"]:
397-
files_to_install = ["libPackageDescription" + g_shared_lib_ext]
398-
if platform.system() == 'Darwin':
399-
files_to_install.append("PackageDescription.swiftinterface")
400-
else:
401-
files_to_install.append("PackageDescription.swiftmodule")
402-
files_to_install.append("PackageDescription.swiftdoc")
403-
404-
for file in files_to_install:
405-
src = os.path.join(runtime_lib_src, runtime, file)
406-
dest = os.path.join(runtime_lib_dest, runtime, file)
407-
mkdir_p(os.path.dirname(dest))
408-
409-
note("Installing %s to %s" % (src, dest))
410-
411-
file_util.copy_file(src, dest, update=1)
412-
413-
files_to_install = ["libPackagePlugin" + g_shared_lib_ext]
414-
if platform.system() == 'Darwin':
415-
files_to_install.append("PackagePlugin.swiftinterface")
416-
else:
417-
files_to_install.append("PackagePlugin.swiftmodule")
418-
files_to_install.append("PackagePlugin.swiftdoc")
419-
420-
for file in files_to_install:
421-
src = os.path.join(runtime_lib_src, file)
422-
dest = os.path.join(runtime_lib_dest, file)
423-
mkdir_p(os.path.dirname(dest))
424-
425-
note("Installing %s to %s" % (src, dest))
426-
427-
file_util.copy_file(src, dest, update=1)
393+
# Install the current variant of PackageDescription.
394+
install_dylib(args, "PackageDescription", os.path.join(prefix, "lib", "swift", "pm", "4_2"), ["PackageDescription"])
395+
396+
# Install the legacy variant of PackageDescription.
397+
args_pd4 = args
398+
args_pd4.build_dir = os.path.join(args.build_dir, "PD4")
399+
install_dylib(args_pd4, "PackageDescription", os.path.join(prefix, "lib", "swift", "pm", "4"), ["PackageDescription"])
400+
401+
# Install PackagePlugin.
402+
install_dylib(args, "PackagePlugin", os.path.join(prefix, "lib", "swift", "pm"), ["PackagePlugin"])
428403

429404

430405
def install_libswiftpm_dylib(args, library_name, install_dir, module_names):
@@ -443,6 +418,18 @@ def install_libswiftpm_dylib(args, library_name, install_dir, module_names):
443418
dir_util.copy_tree(tscclibc_include_dir, tscclibc_include_dir_dest)
444419

445420

421+
def install_dylib(args, library_name, install_dir, module_names):
422+
# Install the dynamic library itself.
423+
# FIXME: Don't hardcode the library prefix.
424+
install_binary(args, "lib" + library_name + g_shared_lib_ext, install_dir)
425+
426+
# Install the swiftmodule/swiftinterface and swiftdoc files for all the modules.
427+
for module in module_names:
428+
install_binary(args, module + ".swiftmodule", install_dir)
429+
if not args.cross_compile_hosts: # When compiling for multiple arches, swiftdoc is part of the swiftmodule directory
430+
install_binary(args, module + ".swiftdoc", install_dir)
431+
432+
446433
def install_binary(args, binary, dest_dir):
447434
src = os.path.join(args.bin_dir, binary)
448435
dest = os.path.join(dest_dir, binary)
@@ -647,8 +634,18 @@ def build_swiftpm_with_swiftpm(args, integrated_swift_driver):
647634

648635
if integrated_swift_driver:
649636
swiftpm_args.append("--use-integrated-swift-driver")
650-
637+
638+
# Build SwiftPM, including libSwiftPM, all the command line tools, and the current variant of PackageDescription.
651639
call_swiftpm(args, swiftpm_args)
640+
641+
# Also build the legacy variant of PackageDescription into a subdirectory of the build directory.
642+
args_pd4 = args
643+
args_pd4.build_dir = os.path.join(args.build_dir, "PD4")
644+
args_pd4.pkgdesc_version = "4"
645+
swiftpm_args_pd4 = swiftpm_args
646+
swiftpm_args_pd4.append("--product")
647+
swiftpm_args_pd4.append("PackageDescription")
648+
call_swiftpm(args_pd4, swiftpm_args_pd4)
652649

653650
# Setup symlinks that'll allow using swiftpm from the build directory.
654651
symlink_force(args.swiftc_path, os.path.join(args.target_dir, args.conf, "swiftc"))
@@ -713,6 +710,7 @@ def get_swiftpm_env_cmd(args):
713710
env_cmd.append("SWIFTPM_LLBUILD_FWK=1")
714711
env_cmd.append("SWIFTCI_USE_LOCAL_DEPS=1")
715712
env_cmd.append("SWIFTPM_MACOS_DEPLOYMENT_TARGET=%s" % g_macos_deployment_target)
713+
env_cmd.append("SWIFTPM_PACKAGE_DESCRIPTION_VERSION=%s" % args.pkgdesc_version)
716714

717715
if args.bootstrap:
718716
libs_joined = ":".join([

0 commit comments

Comments
 (0)