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

build-rust-crate: ensure info about build.rs failures reaches the log #190592

Closed
wants to merge 1 commit into from
Closed

build-rust-crate: ensure info about build.rs failures reaches the log #190592

wants to merge 1 commit into from

Conversation

ghost
Copy link

@ghost ghost commented Sep 10, 2022

Description of changes

When execution of a build.rs script fails, information about the failure is sent to stdout (using "cargo:foo=" prefixes) rather than stderr. Because of this, information needed to diagnose the failure is not available in nix log. An example of that information is found below.

Let's do the simplest thing possible, and replace > with tee so the output of executing build.rs gets copied to the log.

cargo:warning=Could not run `"pkg-config" "--libs" "--cflags" "cairo" "cairo >= 1.14"`
The pkg-config command could not be found.

Most likely, you need to install a pkg-config package for your OS.
Try `apt install pkg-config`, or `yum install pkg-config`,
or `pkg install pkg-config` depending on your distribution.

If you've already installed it, ensure the pkg-config command is one of the
directories in the PATH environment variable.

If you did not expect this build to link to a pre-installed system library,
then check documentation of the cairo-sys-rs crate for an option to
build the library from source, or disable features or dependencies
that require pkg-config.
Things done
  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandbox = true set in nix.conf? (See Nix manual)
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 22.11 Release Notes (or backporting 22.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
    • (Release notes changes) Ran nixos/doc/manual/md-to-db.sh to update generated release notes
  • Fits CONTRIBUTING.md.

When execution of a `build.rs` script fails, information about the failure is
sent to stdout (using "cargo:foo=" prefixes) rather than stderr.  Because of
this, information needed to diagnose the failure is not available in `nix log`.
An example of that information is found below.

Let's do the simplest thing possible, and replace `>` with `tee` so the output
of executing `build.rs` gets copied to the log.

  cargo:warning=Could not run `"pkg-config" "--libs" "--cflags" "cairo" "cairo >= 1.14"`
  The pkg-config command could not be found.

  Most likely, you need to install a pkg-config package for your OS.
  Try `apt install pkg-config`, or `yum install pkg-config`,
  or `pkg install pkg-config` depending on your distribution.

  If you've already installed it, ensure the pkg-config command is one of the
  directories in the PATH environment variable.

  If you did not expect this build to link to a pre-installed system library,
  then check documentation of the cairo-sys-rs crate for an option to
  build the library from source, or disable features or dependencies
  that require pkg-config.
@ofborg ofborg bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild 10.rebuild-linux: 1-10 labels Sep 10, 2022
# build script failures are reported to stdout rather than stderr, so we
# use tee here instead of > to ensure that `nix log` contains useful
# information when a failure occurs
target/build/${crateName}/build_script_build | tee target/build/${crateName}.opt
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this script snippet run with "set -o pipefail"? If it isn't, then the pipe will suppress failures.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for noticing that. How embarrassing. What I wrote would have silently omitted features when the build script fails.

@ghost ghost marked this pull request as draft September 11, 2022 22:24
@ghost ghost closed this Oct 22, 2023
@ghost ghost deleted the pr/build-rust-crate/useful-logs branch October 22, 2023 07:39
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
6.topic: rust 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild 10.rebuild-linux: 1-10
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant