Skip to content

SE-0387: add --toolset option to build-related subcommands #8051

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 7 commits into from
Oct 18, 2024

Conversation

MaxDesiatov
Copy link
Contributor

@MaxDesiatov MaxDesiatov commented Oct 17, 2024

Motivation:

The only feature proposed in SE-0387 that remains unimplemented is the --toolset CLI option:

We propose that users also should be able to pass --toolset <path_to_toolset.json> option to swift build, swift test, and swift run.

We'd like to allow using multiple toolset files at once. This way users can "assemble" toolchains on the fly out of tools that in certain scenarios may even come from different vendors. A toolset file can have an arbitrary name, and each file should be passed with a separate --toolset option, i.e. swift build --toolset t1.json --toolset t2.json.

All of the properties related to names of the tools are optional, which allows merging configuration from multiple
toolset files. For example, consider toolset1.json:

{
 "schemaVersion": "1.0",
 "swiftCompiler": {
   "path": "/usr/bin/swiftc",
   "extraCLIOptions": ["-Xfrontend", "-enable-cxx-interop"]
 },
 "cCompiler": {
   "path": "/usr/bin/clang",
   "extraCLIOptions": ["-pedantic"]
 }
}

and toolset2.json:

{
 "schemaVersion": "1.0",
 "swiftCompiler": {
   "path": "/custom/swiftc"
 }
}

With multiple --toolset options, passing both of those files will merge them into a single configuration. Tools passed in subsequent --toolset options will shadow tools from previous options with the same names. That is,
swift build --toolset toolset1.json --toolset toolset2.json will build with /custom/swiftc and no extra flags, as specified in toolset2.json, but /usr/bin/clang -pedantic from toolset1.json will still be used.

Tools not specified in any of the supplied toolset files will be looked up in existing implied search paths that are used without toolsets, even when rootPath is present. We'd like toolsets to be explicit in this regard: if a tool would like to participate in toolset path lookups, it must provide either a relative or an absolute path in a toolset.

Tools that don't have path property but have extraCLIOptions present will append options from that property to a tool with the same name specified in a preceding toolset file. If no other toolset files were provided, these options will be appended to the default tool invocation.

Modifications:

Added toolsetPaths on LocationOptions, which passes new customToolsets argument on SwiftSDK.deriveTargetSwiftSDK. Added corresponding tests.

Result:

New --toolset option is able to accept toolset JSON files.

@MaxDesiatov MaxDesiatov added cross-compilation test suite improvements to SwiftPM test suite swift test Changes impacting `swift test` tool swift build Changes impacting `swift build` labels Oct 17, 2024
@MaxDesiatov
Copy link
Contributor Author

@swift-ci test

@MaxDesiatov MaxDesiatov changed the title SE-0387: Implement --toolset option on build-related subcommands SE-0387: add --toolset option on build-related subcommands Oct 17, 2024
@MaxDesiatov MaxDesiatov changed the title SE-0387: add --toolset option on build-related subcommands SE-0387: add --toolset option to build-related subcommands Oct 17, 2024
@MaxDesiatov MaxDesiatov requested a review from rauhul October 17, 2024 14:36
@MaxDesiatov
Copy link
Contributor Author

@swift-ci test

@MaxDesiatov
Copy link
Contributor Author

@swift-ci test

@MaxDesiatov
Copy link
Contributor Author

@swift-ci test

@MaxDesiatov
Copy link
Contributor Author

@swift-ci test windows

Copy link
Member

@dschaefer2 dschaefer2 left a comment

Choose a reason for hiding this comment

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

Looks good.

@MaxDesiatov
Copy link
Contributor Author

@swift-ci test

@MaxDesiatov
Copy link
Contributor Author

@swift-ci test windows

@MaxDesiatov MaxDesiatov enabled auto-merge (squash) October 18, 2024 15:03
@MaxDesiatov MaxDesiatov merged commit 4095b90 into main Oct 18, 2024
5 checks passed
@MaxDesiatov MaxDesiatov deleted the maxd/toolset-option branch October 18, 2024 18:46
MaxDesiatov added a commit to MaxDesiatov/swift-evolution that referenced this pull request Oct 18, 2024
With swiftlang/swift-package-manager#8051 merged, the proposal is fully implemented.
DougGregor pushed a commit to swiftlang/swift-evolution that referenced this pull request Oct 21, 2024
ahoppen added a commit to ahoppen/sourcekit-lsp that referenced this pull request Mar 11, 2025
Equivalent to SwiftPM’s `--toolset` option, implemented in swiftlang/swift-package-manager#8051.

Fixes swiftlang#2047
rdar://146557424
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
command-line interface cross-compilation enhancement swift build Changes impacting `swift build` swift test Changes impacting `swift test` tool test suite improvements to SwiftPM test suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants