Repository navigation
Conversation
waltuov
force-pushed
the
feat/tool-command
branch
from
November 11, 2026 16:34
fb89b1c to
2efdf5e
Compare
Contributor
Author
|
CI is red for an unrelated reason. |
…ment Since cc sets the whole environment on the commands it makes, the Debug output of the Command that Tool::to_command, get_archiver and get_ranlib return lists every variable and its value on Unix. Build scripts that print such a command put the environment, secrets included, into build output that Cargo keeps under target/. ToolCommand owns the Command and derefs to it, so it is set up and run the same way, and its Debug output shows only the program and the arguments, like cc's own running: lines. Tool::command, Build::get_archiver_command, Build::try_get_archiver_command, Build::get_ranlib_command and Build::try_get_ranlib_command return it. The existing functions keep returning the same Command as before, and their docs point to the new ones.
waltuov
force-pushed
the
feat/tool-command
branch
from
November 11, 2026 17:59
2efdf5e to
9307a39
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
For #2072.
Since 1.6.0 cc sets the whole environment on the commands it makes, also on the ones it hands out through
Tool::to_command,Build::get_archiverandBuild::get_ranlib. On Unix,Debugfor such aCommandprintsenv -ifollowed by every variable and its value. A build script that prints the command, as libz-sys did withprintln!("running {:?}", cmd), puts the environment into its output, which Cargo keeps undertarget/(GHSA-8p3x-q3q3-q3v5). On Windows, std'sDebugprints only the program and the arguments.This adds
cc::ToolCommand, the wrapper discussed in #2072. It owns theCommandand derefs to it, so it is set up and run like one, andCommand::fromgives theCommandback. ItsDebugoutput is the program and the arguments only, written by the helper behind cc's ownrunning:lines. These functions return it:Tool::commandBuild::get_archiver_commandandBuild::try_get_archiver_commandBuild::get_ranlib_commandandBuild::try_get_ranlib_commandEach one wraps the result of the existing function, so the command itself is the same. A build script that prints the command usually only has to change
to_command()tocommand(), orget_archiver()toget_archiver_command().The five existing functions keep their signatures and return the same
Commandas before, and the environment handling is unchanged. Their docs now say that theDebugoutput lists the environment on Unix and point to the new functions. The logger docs say the same about theCommandpassed asextra.It is a named type so that a helper can take
&mut cc::ToolCommandand keep thatDebug. Returningimpl DerefMut<Target = Command> + Debugwould also work if you prefer a smaller API.Limits:
Commandwith{:?}still lists the environment on Unix: afterCommand::from(cmd), through&mut *cmd, in a function that takes&mut Command, or as the&mut Commandthatcmd.arg(..)returns. The type docs say so.CommandfromTool::to_commandand friends carry whole environment #2072.#[deprecated]onto_commandwould warn when a crate that calls it is built in its own workspace (Cargo caps lints for dependencies) and fail that build under-D warnings. I can add it here or in a later release if you want it.Testing
src/tool.rs:Tool::commandmatchesto_commandin program, arguments and environment, also afterCommand::from.Debugis exactly"cc" "-c" "foo.c"after an argument added through deref, while the snapshot holds a marker variable.tests/get_commands.rs: the same comparison andDebugcheck for both archiver and both ranlib functions. A failing check there doesn't print the environment.{:?}of the plainCommanddoes contain the marker, so they show the difference.cargo testin a CI run in a private repository) the suite passes with and without--features parallel,compile-commands. WithDebugforwarding to the innerCommandthere,tool_command_debug_shows_program_and_args_only,archiver_command_matches_archiverandranlib_command_matches_ranlibfail and the rest passes. On Windows that change can't fail a test, since std'sDebugleaves the environment out there. Not run on macOS.cargo test(default features andparallel,compile-commands), clippy for the Windows andx86_64-unknown-linux-gnutargets and rustdoc with-D warnings.