Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cargo run -v should show setting of LD_LIBRARY_PATH #4879

Closed
joshtriplett opened this issue Dec 30, 2017 · 9 comments · Fixed by #12498
Closed

cargo run -v should show setting of LD_LIBRARY_PATH #4879

joshtriplett opened this issue Dec 30, 2017 · 9 comments · Fixed by #12498
Labels
A-console-output Area: Terminal output, colors, progress bar, etc. C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` Command-run Command-test E-easy Experience: Easy S-accepted Status: Issue or feature is accepted, and has a team member available to help mentor or review

Comments

@joshtriplett
Copy link
Member

joshtriplett commented Dec 30, 2017

I spoke with someone recently who had some trouble figuring out how to run Cargo-built binaries directly, until they realized that cargo run sets LD_LIBRARY_PATH, which is not documented. When running cargo run -v, cargo shows the binaries it runs, but not the setting of LD_LIBRARY_PATH. Please include that in the emitted command line invocations (e.g. LD_LIBRARY_PATH=... target/release/...) when using -v, to make it more obvious what cargo run does.

@alexcrichton alexcrichton added the C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` label Dec 31, 2017
@ehuss
Copy link
Contributor

ehuss commented Apr 10, 2020

LD_LIBRARY_PATH behavior is now documented at https://doc.rust-lang.org/cargo/reference/environment-variables.html#dynamic-library-paths.

cargo run -vv will show all environment variables, including LD_LIBRARY_PATH.

I think it would be good to leave this open for a more programmatic way to get the appropriate paths (some kind of JSON output or something).

@sfackler
Copy link
Member

cargo run -vv only appears to print full command lines for calls to rustc, but the actual run command is still just Running 'target/debug/foo'. Did this regress?

@ehuss
Copy link
Contributor

ehuss commented Feb 17, 2021

Oh, I don't think it ever showed the env vars for the actual running of the executable. I think I was just meaning that the calls to rustc will show it. They are slightly different (between running the exe and building it), so it would probably be good to display it somehow.

@Kobzol
Copy link
Contributor

Kobzol commented Aug 11, 2023

This makes it difficult to debug Rust binaries that use native dependencies and that require LD_LIBRARY_PATH to be set. Without cargo run, the libraries are not found, and I don't know to which directory in target should I point the environment variable. And trying to debug cargo run with gdb doesn't seem to work for me, the program is constantly being stopped on some SIGUSR1 signal (it can be ignored, but still).

It would be nice if cargo run -vv actually emitted the environment flags. I'd like to try to implement it, if you consider it to be useful (and maybe suggest some mentoring tips :) ).

@weihanglo
Copy link
Member

I believe that is feasible to be done.

Basically, search for "Running" string and check if it is really config.extra_verbose(), then set ProcessBuilder::display_env_vars() for the command builder around.

Guess not only cargo run -vv needs that, cargo test -vv could have the same mechanism as well.


@rustbot label +E-easy +S-accepted +Command-test +A-console-output

@rustbot rustbot added A-console-output Area: Terminal output, colors, progress bar, etc. Command-test E-easy Experience: Easy S-accepted Status: Issue or feature is accepted, and has a team member available to help mentor or review labels Aug 14, 2023
@epage
Copy link
Contributor

epage commented Aug 14, 2023

I know this might sound weird but would that be too noisy even for -vv? I'd want to see what it looked like first before committing to it.

@weihanglo
Copy link
Member

Something like below. Note that we already display all environments set for rustc invocation with -vv.

   Compiling verbose-run v0.1.0 (/projects/verbose-run)
     Running `CARGO=/projects/cargo/target/debug/cargo CARGO_BIN_NAME=verbose-run CARGO_CRATE_NAME=verbose-run CARGO_MANIFEST_DIR=/projects/verbose-run CARGO_PKG_AUTHORS='' CARGO_PKG_DESCRIPTION='' CARGO_PKG_HOMEPAGE='' CARGO_PKG_LICENSE='' CARGO_PKG_LICENSE_FILE='' CARGO_PKG_NAME=verbose-run CARGO_PKG_README='' CARGO_PKG_REPOSITORY='' CARGO_PKG_RUST_VERSION='' CARGO_PKG_VERSION=0.1.0 CARGO_PKG_VERSION_MAJOR=0 CARGO_PKG_VERSION_MINOR=1 CARGO_PKG_VERSION_PATCH=0 CARGO_PKG_VERSION_PRE='' CARGO_PRIMARY_PACKAGE=1 DYLD_FALLBACK_LIBRARY_PATH='/projects/verbose-run/target/debug/deps:/Users/whlo/.rustup/toolchains/beta-aarch64-apple-darwin/lib:/Users/whlo/lib:/usr/local/lib:/usr/lib' rustc --crate-name verbose-run --edition=2021 src/main.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=172 --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debuginfo=2 -C split-debuginfo=unpacked -C metadata=99446b492124a920 -C extra-filename=-99446b492124a920 --out-dir /projects/verbose-run/target/debug/deps -C incremental=/projects/verbose-run/target/debug/incremental -L dependency=/projects/verbose-run/target/debug/deps`
    Finished dev [unoptimized + debuginfo] target(s) in 0.46s
     Running `CARGO=/projects/cargo/target/debug/cargo CARGO_MANIFEST_DIR=/projects/verbose-run CARGO_PKG_AUTHORS='' CARGO_PKG_DESCRIPTION='' CARGO_PKG_HOMEPAGE='' CARGO_PKG_LICENSE='' CARGO_PKG_LICENSE_FILE='' CARGO_PKG_NAME=verbose-run CARGO_PKG_README='' CARGO_PKG_REPOSITORY='' CARGO_PKG_RUST_VERSION='' CARGO_PKG_VERSION=0.1.0 CARGO_PKG_VERSION_MAJOR=0 CARGO_PKG_VERSION_MINOR=1 CARGO_PKG_VERSION_PATCH=0 CARGO_PKG_VERSION_PRE='' DYLD_FALLBACK_LIBRARY_PATH='/projects/verbose-run/target/debug/deps:/projects/verbose-run/target/debug:/Users/whlo/.rustup/toolchains/beta-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib:/Users/whlo/lib:/usr/local/lib:/usr/lib' target/debug/verbose-run`
Hello, world!

(Okay GitHub doesn't wrap lines 😕)

@epage
Copy link
Contributor

epage commented Aug 14, 2023

I guess if we are already doing it for rustc, then doing it in this one case isn't too bad. We delineate sections and this is for one of many invocations.

@weihanglo
Copy link
Member

FWIW, #12498 not only supports printing environment variables for cargo run -vv but also cargo test and cargo bench

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-console-output Area: Terminal output, colors, progress bar, etc. C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` Command-run Command-test E-easy Experience: Easy S-accepted Status: Issue or feature is accepted, and has a team member available to help mentor or review
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants