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

Don't panic if rustdoc is missing #64

Merged
merged 2 commits into from
Apr 9, 2024

Conversation

emilal
Copy link
Contributor

@emilal emilal commented Apr 8, 2024

I came here through a rav1e issue and a built issue when trying to build image in a minimal container that doesn't have rustdoc installed; specifically one based on cgr.dev/chainguard/rust:latest.

The error can be produced with the following steps:

  1. cargo new broken
  2. Add the following to Cargo.toml:
[dependencies.rav1e]
version = "0.7.1"
default-features = false
  1. Create a Dockerfile like
FROM cgr.dev/chainguard/rust:latest
WORKDIR /work
COPY Cargo.toml .
COPY src/ src/
RUN cargo build
  1. Run podman build -t broken . and receive output like

error: failed to run custom build command for rav1e v0.7.1

Caused by:
process didn't exit successfully: /work/target/debug/build/rav1e-630d2ba1731d92a3/build-script->build (exit status: 101)
--- stderr
thread 'main' panicked at /home/nonroot/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rav1e-0.7.1/build.rs:250:29:
Failed to acquire build-time information: Os { code: 2, kind: NotFound, message: "No such file or directory" }
note: run with RUST_BACKTRACE=1 environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...
Error: building at STEP "RUN cargo build": while running runtime: exit status 101

To see that the patch eliminates the issue, the steps are similar:

  1. cargo new fixed
  2. Add built with the patch applied somewhere reachable by the coming container build context, e.g. rsync -a /path/to/built/ fixed/
  3. Add the dependency as in broken, and also
[patch.crates-io]
built = { path = "./built" }
  1. Add it to the Dockerfile like
FROM cgr.dev/chainguard/rust:latest
WORKDIR /work
COPY Cargo.toml .
COPY src/ src/
COPY built/ built/
RUN cargo build
  1. Run podman build -t fixed . and see that the build completes successfully.

I don't have any particular opinion about what built should output when rustdoc is missing; my goal here is to successfully build a minimal container image using the image crate.

@emilal
Copy link
Contributor Author

emilal commented Apr 8, 2024

(The default-features=false for rav1e is because otherwise the build will fail due to the image missing nasm, which is irrelevant here.)

@lukaslueg
Copy link
Owner

Thanks for the PR. I suggest to change the behavior here to .unwrap_or_default(), which will result in an empty string; "NOTFOUND" is (hopefully) not a valid binary name, and may fail in weird ways, depending on how the value is used.

Do you happen to know how the base-image is crafted? I fail to see how to install rustc without rustdoc using the rust-provided toolchains.

@emilal
Copy link
Contributor Author

emilal commented Apr 9, 2024

Updated. Though as far as I can tell here it's not the command itself we're changing, but in case running the command fails, I figured the companion to "The output of {rustdoc} -V" could be "NOT FOUND".

I don't know exactly what chainguard is doing to create the image, but it's supposed to be a rather minimal "distroless" image. It's also, according to the doc, supposed to contain rustdoc, so I guess I should send them a notice too. If it is intended, they should likely clarify that the sentence about including rustdoc only applies to the *-dev versions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants