nabijaczleweli / rust-embed-resource

A Cargo build script library to handle compilation and inclusion of Windows resources, in the most resilient fashion imaginable
MIT License
166 stars 29 forks source link

If you build the library and the executable at the same time, embed-resource will fail #42

Closed byeblack closed 2 years ago

byeblack commented 2 years ago

embed-resource fails when lib.rs exists in the project, or [lib] is in Cargo.toml

Windows 10 Rust Version is 1.59.0 embed-resource Version is 1.6.5

noe132 commented 2 years ago

Happened to me as well, when lib.rs presents, the executable built was the same as if embed-resource wasn't used, and no error messages.

nabijaczleweli commented 2 years ago

Do you have a log or an example that reproduces this? I don't really see a reason this shouldn't work, and AFAIK it has done so far?

noe132 commented 2 years ago

@nabijaczleweli https://github.com/noe132/rust-embed-resource-lib-bug run cargo build -r the exe would have no icon delete src/lib.rs and run cargo build -r again the exe would have icon as expected.

Video_2022-02-28_112132

on windows 10 and rust 1.59.0

nabijaczleweli commented 2 years ago

Thanks for the repro!

T:\>git diff withlib nolib
diff --git a/withlib b/nolib
index 095dcfb..26f749f 100644
--- a/withlib
+++ b/nolib
@@ -1,11 +1,10 @@
-T:\rust-embed-resource-lib-bug>cargo build -v > withlib
+T:\rust-embed-resource-lib-bug>cargo build -v > nolib
    Compiling embed-resource v1.6.5
      Running `rustc --crate-name embed_resource D:\Users\nabijaczleweli\.cargo\registry\src\github.com-1ecc6299db9ec823\embed-resource-1.6.5\src\lib.rs --error-format=json --json=diagnostic-rendered-ansi,future-incompat --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debuginfo=2 -C metadata=9adc43b206abdea4 -C extra-filename=-9adc43b206abdea4 --out-dir T:\rust-embed-resource-lib-bug\target\debug\deps -L dependency=T:\rust-embed-resource-lib-bug\target\debug\deps --cap-lints allow`
    Compiling rust-demo v0.1.0 (T:\rust-embed-resource-lib-bug)
      Running `rustc --crate-name build_script_build --edition=2018 build.rs --error-format=json --json=diagnostic-rendered-ansi,future-incompat --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debuginfo=2 -C metadata=2e23cacad8a689e2 -C extra-filename=-2e23cacad8a689e2 --out-dir T:\rust-embed-resource-lib-bug\target\debug\build\rust-demo-2e23cacad8a689e2 -C incremental=T:\rust-embed-resource-lib-bug\target\debug\incremental -L dependency=T:\rust-embed-resource-lib-bug\target\debug\deps --extern embed_resource=T:\rust-embed-resource-lib-bug\target\debug\deps\libembed_resource-9adc43b206abdea4.rlib`
      Running `T:\rust-embed-resource-lib-bug\target\debug\build\rust-demo-2e23cacad8a689e2\build-script-build`
-     Running `rustc --crate-name rust_demo --edition=2018 src\lib.rs --error-format=json --json=diagnostic-rendered-ansi,future-incompat --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debuginfo=2 -C metadata=d71b703fa29c9940 -C extra-filename=-d71b703fa29c9940 --out-dir T:\rust-embed-resource-lib-bug\target\debug\deps -C incremental=T:\rust-embed-resource-lib-bug\target\debug\incremental -L dependency=T:\rust-embed-resource-lib-bug\target\debug\deps -L native=T:\rust-embed-resource-lib-bug\target\debug\build\rust-demo-433fe507bd489039\out -l dylib=icon`
      Running `rustc --crate-name rust_demo --edition=2018 src\main.rs --error-format=json --json=diagnostic-rendered-ansi,future-incompat --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debuginfo=2 -C metadata=904f042c82b0f1c9 -C extra-filename=-904f042c82b0f1c9 --out-dir T:\rust-embed-resource-lib-bug\target\debug\deps -C incremental=T:\rust-embed-resource-lib-bug\target\debug\incremental -L dependency=T:\rust-embed-resource-lib-bug\target\debug\deps
-     --extern rust_demo=T:\rust-embed-resource-lib-bug\target\debug\deps\librust_demo-d71b703fa29c9940.rlib
      -L native=T:\rust-embed-resource-lib-bug\target\debug\build\rust-demo-433fe507bd489039\out
+     -l dylib=icon
     Finished dev [unoptimized + debuginfo] target(s) in s

yeah, confirmed. i thought this would carry over transitively but it .. doesn't (or, maybe, it used to, but doesn't anymore?) – only the library is linked with the resource. hm.

nabijaczleweli commented 2 years ago

Can you try with latest master branch (at least e895286a9ac88c04d113a35dcc09cf615e32e405)? Your PoC worked for me, but I'd be much happier with a confirmation from a real use-case (do note that you need rustc >= 1.50.0, there's no way to fix this in earlier toolchains).

byeblack commented 2 years ago

Can you try with latest master branch (at least e895286)? Your PoC worked for me, but I'd be much happier with a confirmation from a real use-case (do note that you need rustc >= 1.50.0, there's no way to fix this in earlier toolchains).

Thanks a lot, it worked successfully in my project

Windows 10 rustc 1.59.0 MSVC v143

Cargo.toml

[build-dependencies]
embed-resource = { git = "https://github.com/nabijaczleweli/rust-embed-resource", branch = "master" }

[[bin]]
name = "test_bin"
path = "src/main.rs"

[lib]
name = "test"
crate-type = ["staticlib", "cdylib"]
path = "src/lib.rs"
noe132 commented 2 years ago

Works for me too on master 👍

nabijaczleweli commented 2 years ago

Great! Released in v1.6.6.