pants icon indicating copy to clipboard operation
pants copied to clipboard

Add global option `process_extra_env` for every Process call

Open grihabor opened this issue 1 year ago • 9 comments

Precompiled binaries that were not created for NixOS usually have a so-called link-loader hardcoded into them. On Linux/x86_64 this is for example /lib64/ld-linux-x86-64.so.2. for glibc. NixOS, on the other hand, usually has its dynamic linker in the glibc package in the Nix store and therefore cannot run these binaries.

The solution is to use nix-ld, but it only works if you set NIX_LD env variable for every process call.

This pr adds a global option process_extra_env to set arbitrary env variables for every pants Process call.

grihabor avatar Oct 05 '24 21:10 grihabor

Thanks for tackling this!

So we actually already have an option for this: https://www.pantsbuild.org/dev/reference/subsystems/subprocess-environment

The problem is that we only actually apply those env vars in some Python-related processes. But the documentation of that option is very clear that it should apply to all processes. So this is simply broken today.

Therefore, instead of the new option, could you make this existing option apply to all processes, and remove the special handling in the python cases? This would also close https://github.com/pantsbuild/pants/issues/16565 .

benjyw avatar Oct 16 '24 10:10 benjyw

@benjyw I'm getting a bunch of rule errors. It looks like SubprocessEnvironment uses EnvironmentAware class which afaik needs an EnvironmentName which means that I can't use it in the -> Process rule, is this correct? If so, shall we create a different option for Process env vars?

grihabor avatar Oct 21 '24 22:10 grihabor

I've asked @stuhood to take a look at this, as his engine expertise is second to none.

benjyw avatar Oct 31 '24 21:10 benjyw

Thank you!

grihabor avatar Oct 31 '24 21:10 grihabor

@benjyw @stuhood Any updates on this?

grihabor avatar Dec 15 '24 13:12 grihabor

@benjyw @stuhood gently pining again.

cburroughs avatar Jan 09 '25 20:01 cburroughs

Crosslinking some older related discussion in #18382

cburroughs avatar Jan 09 '25 21:01 cburroughs

Thanks for the ping. @stuhood found a minimal repro and workaround for the underlying graph issue, so perhaps that can move this along by allowing this option to be EnvironmentAware.

The remaining question is whether we should in fact make SubprocessEnvironment live up to its documentation by applying to all processes, or whether, since that has been Python-only in practice for a long time, we should deprecate/rename it and start with a new subsystem that either applies globally or can be scoped somehow. See discussion here: https://github.com/pantsbuild/pants/issues/9760#issuecomment-662241354

benjyw avatar Jan 10 '25 00:01 benjyw

If/when this PR can progress, we've just branched for ~2.25 2.26 2.27~ 2.28, so merging this pull request now will come out in ~2.26 2.27 2.28~ 2.29, please move the release notes updates to docs/notes/2.29.x.md. Thank you!

huonw avatar Feb 06 '25 03:02 huonw

Thanks for the contribution. We've just branched for 2.30.x, so merging this pull request now will come out in 2.31.x (but be backported as requested). Please move the release notes updates to docs/notes/2.31.x.md if that's appropriate.

That said, now that we're entirely call-by-name you should be able to avoid graph issues.

benjyw avatar Oct 29 '25 00:10 benjyw