Skip to content

Commit 583ca3d

Browse files
committed
Fix missing-docs lint on dummy build.rs
This ensures the dummy `build.rs` (which contains an empty `main()` function) passes the `missing-docs` lint check from rustc Fixes #377
1 parent 8d97452 commit 583ca3d

File tree

6 files changed

+47
-4
lines changed

6 files changed

+47
-4
lines changed

lib.nix

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,15 +191,21 @@ rec
191191
pushd $out/$member > /dev/null
192192
mkdir -p src
193193
194-
# Avoid accidentally pulling `std` for no-std crates.
195-
echo '#![no_std]' >src/lib.rs
196-
197194
# pretend there's a `build.rs`, otherwise cargo doesn't build
198195
# the `[build-dependencies]`. Custom locations of build scripts
199196
# aren't an issue because we strip the `build` field in
200197
# `fixupCargoToml`; so cargo always thinks there's a build
201198
# script which is `./build.rs`.
202-
echo 'fn main() {}' > build.rs
199+
# We also add documentation to avoid rustc complaining about
200+
# missing documentation: https://github.com/nix-community/naersk/issues/377
201+
echo '//! stub crate' > build.rs
202+
echo '/// stub main function' >> build.rs
203+
echo 'fn main() {}' >> build.rs
204+
205+
# Avoid accidentally pulling `std` for no-std crates.
206+
echo '//! stub lib' >src/lib.rs
207+
echo '#![no_std]' >>src/lib.rs
208+
203209
popd > /dev/null
204210
done
205211

test/fast/default.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
git-dep-dup = pkgs.callPackage ./git-dep-dup { inherit naersk; };
1313
git-single-repository-with-multiple-crates = pkgs.callPackage ./git-single-repository-with-multiple-crates { inherit naersk; };
1414
git-symlink = pkgs.callPackage ./git-symlink { inherit naersk; };
15+
stub-lints = pkgs.callPackage ./stub-lints { inherit naersk; };
1516
openssl = pkgs.callPackage ./openssl { inherit naersk; };
1617
post-install-hook = pkgs.callPackage ./post-install-hook { inherit naersk; };
1718
readme = pkgs.callPackage ./readme { inherit naersk; };

test/fast/stub-lints/default.nix

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{ naersk, ... }:
2+
3+
naersk.buildPackage {
4+
src = ./fixtures;
5+
doCheck = true;
6+
7+
# we instruct cargo to error out if the 'missing-docs' lint is triggered. At the time of writing
8+
# (30-01-2026) this is the only documentation lint that rustc looks for:
9+
#
10+
# > Note that, except for missing_docs, these lints are only available when running rustdoc, not rustc.
11+
# > [https://doc.rust-lang.org/rustdoc/lints.html#lints]
12+
CARGO_BUILD_RUSTFLAGS = "-D missing-docs"; # error out if 'missing-docs' is triggered
13+
}

test/fast/stub-lints/fixtures/Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Tests that the stub/dummy "build.rs" does not fail on rustc lints
2+
# https://github.com/nix-community/naersk/issues/377
3+
4+
[package]
5+
name = "stub-lints"
6+
version = "0.1.0"
7+
authors = ["nicolas <nicolas@nmattia.com>"]
8+
edition = "2018"
9+
10+
[dependencies]
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//! Hello world!
2+
3+
/// Says hello
4+
fn main() {
5+
println!("Hello, world!");
6+
}

0 commit comments

Comments
 (0)