-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Description
Description
Working on Swift projects in VS Code has an annoying side effect, which is that switching between building within VS Code to building on the command-line basically leads to a full rebuild of the whole projects. That's presumably because environment variables are slightly different in both environments. That's what I learned from a lengthy thread in the Swift Open Source Slack.
Working without a manual --scratch-path in one or the other environment is therefore impossible (or very annoying). This, however, leads to 3 build locations (VS Code build, command-line build, index build) which host more or less the same build artifacts independently.
Expected behavior
One possible solution brought up by @MaxDesiatov is a mode for swift build (and perhaps other commands) that basically says "ignore all environment variables". Given that the same toolchain, compiler and compile options are in use, the same build folder could be used no matter from which environment the build got triggered.
This could also be helpful to make a package independent from the build context. Accessing environment variables from within manifest files would be an error or at least it would be in the user's responsibility to make sure there happens to be no access in the package's manifest and the manifests of all dependencies.
Actual behavior
Environment variables are the most volatile and uncontrollable influence on a build and cause regular rebuilds. Environments variables altering the build outcome is probably generally not a good pattern. The option could shield the build from outside influences.
Steps to reproduce
- Make sure to use the same build toolchain in VS Code and the command-line.
- Build in VS Code.
- Build from the command-line.
- Notice how a complete rebuild is performed.
Swift Package Manager version/commit hash
6.2.1
Swift & OS version (output of swift --version && uname -a)
Apple Swift version 6.2.1 (swift-6.2.1-RELEASE)
Darwin Kernel Version 25.1.0, macOS 26.1