Skip to content

Always build SwiftSyntax as a static library #323

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
Oct 13, 2021
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
16 changes: 3 additions & 13 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,6 @@ if ProcessInfo.processInfo.environment["SWIFT_BUILD_SCRIPT_ENVIRONMENT"] != nil

package.targets.append(swiftSyntaxTarget)

let libraryType: Product.Library.LibraryType

/// When we're in a build-script environment, we want to build a dylib instead
/// of a static library since we install the dylib into the toolchain.
if ProcessInfo.processInfo.environment["SWIFT_BUILD_SCRIPT_ENVIRONMENT"] != nil {
libraryType = .dynamic
} else {
libraryType = .static
}

package.products.append(.library(name: "SwiftSyntax", type: libraryType, targets: ["SwiftSyntax"]))
package.products.append(.library(name: "SwiftSyntaxParser", type: libraryType, targets: ["SwiftSyntaxParser"]))
package.products.append(.library(name: "SwiftSyntaxBuilder", type: libraryType, targets: ["SwiftSyntaxBuilder"]))
package.products.append(.library(name: "SwiftSyntax", type: .static, targets: ["SwiftSyntax"]))
package.products.append(.library(name: "SwiftSyntaxParser", type: .static, targets: ["SwiftSyntaxParser"]))
package.products.append(.library(name: "SwiftSyntaxBuilder", type: .static, targets: ["SwiftSyntaxBuilder"]))
79 changes: 0 additions & 79 deletions build-script.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,10 +325,6 @@ def clear_gyb_files_from_previous_run(sources_dir, destination_dir, verbose):
# Building SwiftSyntax


def get_installed_dylib_names():
return ["libSwiftSyntax.dylib", "libSwiftSyntaxParser.dylib"]


def get_swiftpm_invocation(toolchain, action, build_dir, multiroot_data_file, release):
swift_exec = os.path.join(toolchain, "bin", "swift")

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


def delete_rpath(rpath, binary):
if platform.system() == "Darwin":
cmd = ["install_name_tool", "-delete_rpath", rpath, binary]
note("removing RPATH from %s: %s" % (binary, " ".join(cmd)))
subprocess.call(cmd)
else:
fatal_error("unable to remove RPATHs on this platform")


def change_id_rpath(rpath, binary):
if platform.system() == "Darwin":
cmd = ["install_name_tool", "-id", rpath, binary]
note("changing id in %s: %s" % (binary, " ".join(cmd)))
result = subprocess.call(cmd)
if result != 0:
fatal_error("command failed with exit status %d" % (result,))
else:
fatal_error("unable to invoke install_name_tool on this platform")


def check_and_sync(file_path, install_path):
cmd = ["rsync", "-a", file_path, install_path]
note("installing %s: %s" % (os.path.basename(file_path), " ".join(cmd)))
result = subprocess.check_call(cmd)
if result != 0:
fatal_error("install failed with exit status %d" % (result,))


def install(build_dir, dylib_dir, stdlib_rpath):
for dylib_name in get_installed_dylib_names():

dylib_path = os.path.join(build_dir, dylib_name)

# users should find the dylib as if it's a part of stdlib.
change_id_rpath(os.path.join("@rpath", dylib_name), dylib_path)

# we don't wanna hard-code the stdlib dylibs into rpath.
delete_rpath(stdlib_rpath, dylib_path)
check_and_sync(
file_path=dylib_path, install_path=os.path.join(dylib_dir, dylib_name)
)


# -----------------------------------------------------------------------------
# Arugment Parsing

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

# -------------------------------------------------------------------------
install_group = parser.add_argument_group("Install")

install_group.add_argument(
"-i",
"--install",
action="store_true",
help="Install the build artifact to a specified toolchain directory.",
)

install_group.add_argument(
"--dylib-dir", help="The directory to where the .dylib should be installed."
)

# -------------------------------------------------------------------------
test_group = parser.add_argument_group("Test")

Expand Down Expand Up @@ -771,24 +710,6 @@ def parse_args():
def main():
args = parse_args()

if args.install:
if not args.dylib_dir:
fatal_error("Must specify directory to install (--dylib-dir)")
if not args.build_dir:
fatal_error("Must specify build directory to copy from (--build-dir)")
if args.release:
build_dir = os.path.join(args.build_dir, "release")
else:
# will this ever happen?
build_dir = os.path.join(args.build_dir, "debug")
stdlib_rpath = os.path.join(args.toolchain, "lib", "swift", "macosx")
install(
build_dir=build_dir,
dylib_dir=args.dylib_dir,
stdlib_rpath=stdlib_rpath,
)
sys.exit(0)

try:
if not args.verify_generated_files:
generate_gyb_files(
Expand Down