Skip to content

Conversation

@alex-reilly-dd
Copy link

@alex-reilly-dd alex-reilly-dd commented Dec 25, 2025

Summary

  • Add --env NAME=VALUE argument to forward environment variables through the Swift Package Manager plugin sandbox
  • Create withEnvironment helper functions to build environment arrays for posix_spawn that include extra variables
  • Update posix_spawn calls in both BenchmarkCommandPlugin and BenchmarkTool to use the custom environment

This is needed because SPM plugins run in a sandboxed environment that strips DYLD_* and other environment variables. The new --env argument allows users to explicitly pass through environment variables that would otherwise be lost.

Why this is needed

The issue is the SPM plugin sandbox. Here's the chain:

User's shell (has DYLD_* vars)
    ↓
swift package benchmark --env DYLD_INSERT_LIBRARIES=...
    ↓
SPM Plugin Sandbox ← strips DYLD_* and other "dangerous" vars
    ↓
BenchmarkCommandPlugin (environ is already stripped here)
    ↓
BenchmarkTool (inherits stripped environ)
    ↓
Benchmark executables (no DYLD_* vars)

By the time BenchmarkCommandPlugin runs, Apple's sandbox has already removed DYLD_* variables from environ for security reasons. The --env flag works around this by letting users explicitly specify variables as command-line arguments, which bypass the environment stripping.

Test plan

  • Verify --env VAR=value passes through to benchmark subprocesses
  • Verify existing functionality without --env continues to work

Test results

  • Unit tests: 10 new tests in EnvironmentForwardingTests.swift verify the environment building logic
  • Integration test: Verified --env correctly passes variables to subprocesses via posix_spawn
  • Regression test: Ran existing benchmarks without --env to confirm no breaking changes

🤖 Generated with Claude Code

alex-reilly-dd and others added 2 commits December 24, 2025 21:31
Tests the withEnvironment helper functions that enable passing environment
variables through the SPM plugin sandbox via --env arguments.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@alex-reilly-dd alex-reilly-dd changed the title Add environment variable forwarding through plugin sandbox feat: Add environment variable forwarding through plugin sandbox Dec 25, 2025
@alex-reilly-dd
Copy link
Author

Working on getting tests passing locally. I'll take this out of draft mode when it's ready for review.

The use case is that I'm working on a project and working on a fork of the swift compiler in parallel, so I need benchmarks to run with the development build of my toolchain.

@alex-reilly-dd alex-reilly-dd marked this pull request as ready for review December 25, 2025 19:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant