Skip to content

SWIFT_DRIVER_SWIFT_FRONTEND_EXEC Ignored by swift-build system #855

@rjmansfield

Description

@rjmansfield

When building with the Swift Build System (--build-system swiftbuild), the environment variable SWIFT_DRIVER_SWIFT_FRONTEND_EXEC is ignored. As a result, swift build always invokes the system toolchain’s swift-frontend instead of the custom frontend specified by the environment variable.

Steps to Reproduce

Create a simple Swift package:

mkdir -p /tmp/swiftbuild-env-test && cd /tmp/swiftbuild-env-test
swift package init --type executable --name EnvTest

Test 1: Native Build System (works)

cd /tmp/swiftbuild-env-test
rm -rf .build
# Use a custom swift-frontend and pass -Xswiftc -v to confirm
env SWIFT_DRIVER_SWIFT_FRONTEND_EXEC=/Users/ryan_mansfield/swift/build/Ninja-RelWithDebInfoAssert/swift-macosx-arm64/bin/swift-frontend \
  swift build -Xswiftc -v 2>&1 | grep "swift-frontend.*-frontend.*-c" | head -1

Result:

Shows the custom frontend being used:
/Users/ryan_mansfield/swift/build/Ninja-RelWithDebInfoAssert/swift-macosx-arm64/bin/swift-frontend -frontend -c -primary-file /private/tmp/swiftbuild-env-test/Sources/EnvTest/main.swift ...

Test 2: Swift Build System (doesn't work)

cd /tmp/swiftbuild-env-test
rm -rf .build

# Use the same custom frontend with the Swift Build system
env SWIFT_DRIVER_SWIFT_FRONTEND_EXEC=/Users/ryan_mansfield/swift/build/Ninja-RelWithDebInfoAssert/swift-macosx-arm64/bin/swift-frontend \
  swift build --build-system swiftbuild -Xswiftc -v 2>&1 | grep "swift-frontend.*-frontend.*-c" | head -1

Result:

The system toolchain frontend is used instead:

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend -frontend -c -primary-file /private/tmp/swiftbuild-env-test/Sources/EnvTest/main.swift ...

Expected Behavior

swift build should respect the SWIFT_DRIVER_SWIFT_FRONTEND_EXEC environment variable and use the specified custom swift-frontend for all compilation tasks, regardless of the build system used.

Actual Behavior
When using the Swift Build System (--build-system swiftbuild), the SWIFT_DRIVER_SWIFT_FRONTEND_EXEC environment variable is ignored, and the system toolchain’s swift-frontend is always used.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions