Skip to content

Commit 0580323

Browse files
blckngmindygreg
authored andcommitted
Workaround docs.rs build failure
1 parent b799275 commit 0580323

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

Cargo.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,13 @@ winapi = {version = "0.3", features = ["minwindef"] }
1919

2020
[build-dependencies]
2121
cc = "1.0"
22+
23+
[package.metadata.docs.rs]
24+
default-target = "x86_64-pc-windows-msvc"
25+
targets = ["x86_64-pc-windows-msvc"]
26+
# Docs.rs does not have a C cross compiler for windows. This cfg is set so that
27+
# build.rs can know that it is in a docs.rs build and skip C compilation.
28+
#
29+
# https://github.com/rust-lang/docs.rs/issues/147#issuecomment-389544407
30+
rustc-args = ["--cfg", "memory_module_sys_docs_rs"]
31+
rustdoc-args = ["--cfg", "memory_module_sys_docs_rs"]

build.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
fn main() {
2-
println!("cargo:rerun-if-changed=src/memorymodule.c");
3-
println!("cargo:rerun-if-changed=src/memorymodule.h");
2+
// Skip C compilation if building on docs.rs.
3+
if cfg!(not(memory_module_sys_docs_rs)) {
4+
println!("cargo:rerun-if-changed=src/memorymodule.c");
5+
println!("cargo:rerun-if-changed=src/memorymodule.h");
46

5-
cc::Build::new()
6-
.file("src/memorymodule.c")
7-
.compile("memorymodule");
7+
cc::Build::new()
8+
.file("src/memorymodule.c")
9+
.compile("memorymodule");
10+
}
811
}

0 commit comments

Comments
 (0)