Skip to content
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

[SR-6164] swift build ignores -Xswiftc -Ounchecked (and other options) #4937

Closed
swift-ci opened this issue Oct 16, 2017 · 9 comments
Closed
Labels

Comments

@swift-ci
Copy link
Contributor

Previous ID SR-6164
Radar None
Original Reporter nettlep (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

$ swift --version
Apple Swift version 4.0 (swiftlang-900.0.65 clang-900.0.37)
Target: x86_64-apple-macosx10.9

MacBook Pro (Retina, 15-inch, Late 2013) running macOS 10.13

Additional Detail from JIRA
Votes 0
Component/s Package Manager
Labels Bug, StarterBug
Assignee None
Priority Medium

md5: 879fbacbb30f1f3953caeaf00253dd83

Issue Description:

What it does:

Issuing the command swift build -c release -Ounchecked does not result in a build with runtime safety checks removed.

According to BuildPlan.swift, the default optimization arguments for the build configuration (either -Onone -g -enable-testing for debug builds or -O for release builds) always come after the options specified on the command-line, causing the developer-specified options for optimizations to be overridden.

In addition, -j<threads> is also overridden as well as others.

What it should do:

According to the swift build --help the option -Xswiftc is documented as Pass flag through to all Swift compiler invocations. As no exceptions are specified, it is assumed that all options are passed through, including those for optimizations.

Ideally, the developer-specified command-line options last on the command line to avoid confusion. If this is not possible for all options, then a warning should be presented to inform the developer that their option has been overridden.

@ankitspd
Copy link
Member

The correct solution is build settings but this should be easy to change order of arguments.

@swift-ci
Copy link
Contributor Author

Comment by Paul Nettle (JIRA)

Side note: A terrible workaround -

I've been through the relevant parts of the SPM code and haven't found a way to inject the necessary options after the default optimization settings. The final compilation options used are placed into a YAML file in the .build directory, but I don't see a way to inject a process to modify that file before compilation is initiated (possibly one of the debug driver options can be used?)

So, for the time being I'm working around this by running swift build -c release as normal. Once the build finishes, I run a script which effectively modifies the YAML file and then re-builds. It looks something like this:

sed -i "" 's/"-O",/"-Ounchecked",/g' .build/release.yaml
rm -rf .build/release/Foo.build
rm -f .build/release/Foo
/path/to/swift-build-tool -f .build/release.yaml main -v

This is far from ideal as it requires a complete rebuild of the project (in my case, multiple modules for multiple platforms using multiple toolchains.) Yet, I will continue to do this as performance in this project is critical and this optimization provides an effective 20% perf boost.

Disclaimer: I've thoroughly tested this code to ensure that the runtime safety checks are not needed. Where necessary, I include my own logic to avoid problematic conditions.

@ankitspd
Copy link
Member

Ah, we don't need to modify the YAML after the fact, we need to update the BuildPlan and change the order of the arguments that are generated.

@swift-ci
Copy link
Contributor Author

Comment by Paul Nettle (JIRA)

@aciidb0mb3r - Agreed. However, I'm trying to avoid having to hack & rebuild the package manager. In my case, I'm using multiple toolchains and I don't know that I can successfully rebuild them all.

If you have any clever suggestions for temporary workarounds until I'm able to get updated toolchains, I'd love to hear them.

@ankitspd
Copy link
Member

Hm, unfortunately no. You could build swiftpm with those toolchains and then use that but that can be very annoying.

@belkadan
Copy link

FWIW I agree with Paul that -X* options should always come last.

@ankitspd
Copy link
Member

#1365

@swift-ci
Copy link
Contributor Author

Comment by Paul Nettle (JIRA)

The change covers Xswiftc, -Xcc -XLinker options, but I'm not sure it covers -Xcxx flags.

Added a PR to cover this: #1380

@ankitspd
Copy link
Member

#1380

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 4, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants