Skip to content

Commit 8bb2f8b

Browse files
authored
Merge pull request #323 from ahoppen/pr/build-swiftsyntax-statically
Always build SwiftSyntax as a static library
2 parents ab89001 + 4dbd190 commit 8bb2f8b

File tree

2 files changed

+3
-92
lines changed

2 files changed

+3
-92
lines changed

Package.swift

+3-13
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,6 @@ if ProcessInfo.processInfo.environment["SWIFT_BUILD_SCRIPT_ENVIRONMENT"] != nil
4343

4444
package.targets.append(swiftSyntaxTarget)
4545

46-
let libraryType: Product.Library.LibraryType
47-
48-
/// When we're in a build-script environment, we want to build a dylib instead
49-
/// of a static library since we install the dylib into the toolchain.
50-
if ProcessInfo.processInfo.environment["SWIFT_BUILD_SCRIPT_ENVIRONMENT"] != nil {
51-
libraryType = .dynamic
52-
} else {
53-
libraryType = .static
54-
}
55-
56-
package.products.append(.library(name: "SwiftSyntax", type: libraryType, targets: ["SwiftSyntax"]))
57-
package.products.append(.library(name: "SwiftSyntaxParser", type: libraryType, targets: ["SwiftSyntaxParser"]))
58-
package.products.append(.library(name: "SwiftSyntaxBuilder", type: libraryType, targets: ["SwiftSyntaxBuilder"]))
46+
package.products.append(.library(name: "SwiftSyntax", type: .static, targets: ["SwiftSyntax"]))
47+
package.products.append(.library(name: "SwiftSyntaxParser", type: .static, targets: ["SwiftSyntaxParser"]))
48+
package.products.append(.library(name: "SwiftSyntaxBuilder", type: .static, targets: ["SwiftSyntaxBuilder"]))

build-script.py

-79
Original file line numberDiff line numberDiff line change
@@ -325,10 +325,6 @@ def clear_gyb_files_from_previous_run(sources_dir, destination_dir, verbose):
325325
# Building SwiftSyntax
326326

327327

328-
def get_installed_dylib_names():
329-
return ["libSwiftSyntax.dylib", "libSwiftSyntaxParser.dylib"]
330-
331-
332328
def get_swiftpm_invocation(toolchain, action, build_dir, multiroot_data_file, release):
333329
swift_exec = os.path.join(toolchain, "bin", "swift")
334330

@@ -579,49 +575,6 @@ def run_xctests(toolchain, build_dir, multiroot_data_file, release, verbose):
579575
return call(swiftpm_call, env=env, verbose=verbose) == 0
580576

581577

582-
def delete_rpath(rpath, binary):
583-
if platform.system() == "Darwin":
584-
cmd = ["install_name_tool", "-delete_rpath", rpath, binary]
585-
note("removing RPATH from %s: %s" % (binary, " ".join(cmd)))
586-
subprocess.call(cmd)
587-
else:
588-
fatal_error("unable to remove RPATHs on this platform")
589-
590-
591-
def change_id_rpath(rpath, binary):
592-
if platform.system() == "Darwin":
593-
cmd = ["install_name_tool", "-id", rpath, binary]
594-
note("changing id in %s: %s" % (binary, " ".join(cmd)))
595-
result = subprocess.call(cmd)
596-
if result != 0:
597-
fatal_error("command failed with exit status %d" % (result,))
598-
else:
599-
fatal_error("unable to invoke install_name_tool on this platform")
600-
601-
602-
def check_and_sync(file_path, install_path):
603-
cmd = ["rsync", "-a", file_path, install_path]
604-
note("installing %s: %s" % (os.path.basename(file_path), " ".join(cmd)))
605-
result = subprocess.check_call(cmd)
606-
if result != 0:
607-
fatal_error("install failed with exit status %d" % (result,))
608-
609-
610-
def install(build_dir, dylib_dir, stdlib_rpath):
611-
for dylib_name in get_installed_dylib_names():
612-
613-
dylib_path = os.path.join(build_dir, dylib_name)
614-
615-
# users should find the dylib as if it's a part of stdlib.
616-
change_id_rpath(os.path.join("@rpath", dylib_name), dylib_path)
617-
618-
# we don't wanna hard-code the stdlib dylibs into rpath.
619-
delete_rpath(stdlib_rpath, dylib_path)
620-
check_and_sync(
621-
file_path=dylib_path, install_path=os.path.join(dylib_dir, dylib_name)
622-
)
623-
624-
625578
# -----------------------------------------------------------------------------
626579
# Arugment Parsing
627580

@@ -717,20 +670,6 @@ def parse_args():
717670
help="The path to the toolchain that shall be used to build " "SwiftSyntax.",
718671
)
719672

720-
# -------------------------------------------------------------------------
721-
install_group = parser.add_argument_group("Install")
722-
723-
install_group.add_argument(
724-
"-i",
725-
"--install",
726-
action="store_true",
727-
help="Install the build artifact to a specified toolchain directory.",
728-
)
729-
730-
install_group.add_argument(
731-
"--dylib-dir", help="The directory to where the .dylib should be installed."
732-
)
733-
734673
# -------------------------------------------------------------------------
735674
test_group = parser.add_argument_group("Test")
736675

@@ -771,24 +710,6 @@ def parse_args():
771710
def main():
772711
args = parse_args()
773712

774-
if args.install:
775-
if not args.dylib_dir:
776-
fatal_error("Must specify directory to install (--dylib-dir)")
777-
if not args.build_dir:
778-
fatal_error("Must specify build directory to copy from (--build-dir)")
779-
if args.release:
780-
build_dir = os.path.join(args.build_dir, "release")
781-
else:
782-
# will this ever happen?
783-
build_dir = os.path.join(args.build_dir, "debug")
784-
stdlib_rpath = os.path.join(args.toolchain, "lib", "swift", "macosx")
785-
install(
786-
build_dir=build_dir,
787-
dylib_dir=args.dylib_dir,
788-
stdlib_rpath=stdlib_rpath,
789-
)
790-
sys.exit(0)
791-
792713
try:
793714
if not args.verify_generated_files:
794715
generate_gyb_files(

0 commit comments

Comments
 (0)