tauri-apps / winres

Create and set windows icons and metadata for executables with a rust build script
MIT License
7 stars 6 forks source link

Could not open resource.rc when using compile_for #11

Open xNyaDev opened 1 year ago

xNyaDev commented 1 year ago

I am trying to use tauri_winres to add resources to a single binary using the new compile_for method added in 0.1.1. I am using the following code:

fn main() {
    #[cfg(feature = "cli")]
    if std::env::var("CARGO_CFG_TARGET_OS").unwrap() == "windows" {
        tauri_winres::WindowsResource::new()
            .set("FileDescription", "bfstool-cli")
            .set(
                "LegalCopyright",
                "Licensed under MIT or Apache-2.0, xNyaDev 2023",
            )
            .set("OriginalFilename", "bfstool-cli.exe")
            .set("ProductName", "bfstool-cli")
            .compile_for(&["bfstool-cli"])
            .unwrap();
    }
}

My crate is a Rust library (no cdylib) with a single binary target. Running cargo build results in:

   Compiling bfstool v2.0.0 (C:\Users\xNya\Documents\Projects\bfstool)
error: failed to run custom build command for `bfstool v2.0.0 (C:\Users\xNya\Documents\Projects\bfstool)`

Caused by:
  process didn't exit successfully: `C:\Users\xNya\Documents\Projects\bfstool\target\debug\build\bfstool-cfbe2ae6d3aaf1dc\build-script-build` (exit code: 101)
  --- stdout
  package.metadata does not exist
  Microsoft (R) Windows (R) Resource Compiler Version 10.0.10011.16384
  Copyright (C) Microsoft Corporation.  All rights reserved.

  fatal error RC1110: could not open resource.rc

  --- stderr
  thread 'main' panicked at 'RC.EXE failed to compile specified resource file', C:\Users\xNya\.cargo\registry\src\index.crates.io-6f17d22bba15001f\embed-resource-2.1.1\src\windows_msvc.rs:39:13
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

The line package.metadata does not exist is expected as my Cargo.toml contains no resource fields and everything is set in the above build script.

If you need the entire crate to reproduce the issue, the source code is located here: https://github.com/xNyaDev/bfstool. It is currently using the code I wrote for #8 (and therefore builds fine), changing it to upstream requires modifying Cargo.toml to use tauri-winres 0.1.1 and changing the compile_for call in the build script.

FabianLars commented 1 year ago

Thanks for the report! So far i'm still trying to figure out why this happens but in the meantime i wanted to note that using compile() instead of compile_for should work too now that we use embed-resource since it only compiles the resource for binaries if there is a mix of bins and libs in the project.