Skip to content

Don’t include the toolchain rpath when installing swift-format #680

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
Jan 23, 2024
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
21 changes: 20 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,24 @@
import Foundation
import PackageDescription

// MARK: - Parse build arguments

func hasEnvironmentVariable(_ name: String) -> Bool {
Copy link
Member

Choose a reason for hiding this comment

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

You can also update the SWIFTCI_USE_LOCAL_DEPS env var lookup at the bottom of the file to use this.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch. I’ll do it in a follow-up PR.

return ProcessInfo.processInfo.environment[name] != nil
}

// When building the toolchain on the CI, don't add the CI's runpath for the
// final build before installing.
let installAction = hasEnvironmentVariable("SOURCEKIT_LSP_CI_INSTALL")


// MARK: - Compute custom build settings

var swiftformatLinkSettings: [LinkerSetting] = []
if installAction {
swiftformatLinkSettings += [.unsafeFlags(["-no-toolchain-stdlib-rpath"], .when(platforms: [.linux, .android]))]
}

let package = Package(
name: "swift-format",
platforms: [
Expand Down Expand Up @@ -106,7 +124,8 @@ let package = Package(
.product(name: "ArgumentParser", package: "swift-argument-parser"),
.product(name: "SwiftSyntax", package: "swift-syntax"),
.product(name: "SwiftParser", package: "swift-syntax"),
]
],
linkerSettings: swiftformatLinkSettings
Copy link
Member

Choose a reason for hiding this comment

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

Can this be made into a function that returns the desired value, so that its definition can be moved down to the bottom of the file? That way there's no noise before the package definition itself that average users don't care about.

Copy link
Member Author

Choose a reason for hiding this comment

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

My goal was to keep the structure similar to that of sourcekit-lsp’s Package.swift and swift-syntax’s Package.swift for consistency across the toolchain packages.

I think moving those variables to be functions at the bottom of the file might be a good idea but I’d like to try that across all three packages first and see if it works for all of them. I’ll do it in a follow-up PR.

),

.testTarget(
Expand Down
10 changes: 6 additions & 4 deletions build-script-helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,11 @@ def get_swiftpm_options(
return args


def get_swiftpm_environment_variables():
def get_swiftpm_environment_variables(action: str):
env = dict(os.environ)
env["SWIFTCI_USE_LOCAL_DEPS"] = "1"
if action == "install":
env["SOURCEKIT_LSP_CI_INSTALL"] = "1"
return env


Expand Down Expand Up @@ -194,7 +196,7 @@ def invoke_swiftpm(

def build(args: argparse.Namespace) -> None:
print("** Building swift-format **")
env = get_swiftpm_environment_variables()
env = get_swiftpm_environment_variables(args.action)
invoke_swiftpm(
package_path=args.package_path,
swift_exec=args.swift_exec,
Expand All @@ -212,7 +214,7 @@ def build(args: argparse.Namespace) -> None:

def test(args: argparse.Namespace) -> None:
print("** Testing swift-format **")
env = get_swiftpm_environment_variables()
env = get_swiftpm_environment_variables(args.action)
invoke_swiftpm(
package_path=args.package_path,
swift_exec=args.swift_exec,
Expand All @@ -233,7 +235,7 @@ def install(args: argparse.Namespace) -> None:

print("** Installing swift-format **")

env = get_swiftpm_environment_variables()
env = get_swiftpm_environment_variables(args.action)
swiftpm_args = get_swiftpm_options(
swift_exec=args.swift_exec,
package_path=args.package_path,
Expand Down