実現したいこと
- windows 向けビルド時のみwinres モジュールを利用してアイコンを設定したい。
- wasm向けビルド時の時はwinresモジュールを一切含めたくない。
前提
rustでクロスプラットフォームなappを作りたいと思い、eguiを含むソフトをビルドしようとしている。
windows プラットフォームのビルド時のみ winres パッケージを読み込んでicon を指定したい。
発生している問題・エラーメッセージ
note: rust-lld: error: unable to find library -licon.res error: could not compile `ソフト名` due to previous error 2023-04-23T01:23:40.268952Z ERROR error error from HTML pipeline Caused by: 0: error from asset pipeline 1: error during cargo build execution 2: cargo call returned a bad status Error: error from HTML pipeline Caused by: 0: error from asset pipeline 1: error during cargo build execution 2: cargo call returned a bad status
該当のソースコード
build.rs
1#[cfg(target_family="windows")] 2fn only_win(){ 3 use windres::Build; 4 Build::new().compile("assets/icon.rc").unwrap(); 5} 6 7fn main() { 8 #[cfg(target_family="windows")] 9 only_win(); 10}
Cargo.toml
1[package] 2name = "ソフト名" 3version = "0.1.0" 4authors = ["名前"] 5edition = "2021" 6rust-version = "1.68" 7build = "build.rs" 8 9 10[dependencies] 11egui = "0.21.0" 12eframe = { version = "0.21.0", default-features = false, features = [ 13 "accesskit", # Make egui comptaible with screen readers. NOTE: adds a lot of dependencies. 14 "default_fonts", # Embed the default egui fonts. 15 "glow", # Use the glow rendering backend. Alternative: "wgpu". 16 "persistence", # Enable restoring app state when restarting the app. 17] } 18kira = "0.7.3" 19 20# You only need serde if you want app persistence: 21serde = { version = "1", features = ["derive"] } 22 23# native: 24[target.'cfg(not(target_arch = "wasm32"))'.dependencies] 25tracing-subscriber = "0.3" 26 27# web: 28[target.'cfg(target_arch = "wasm32")'.dependencies] 29console_error_panic_hook = "0.1.6" 30tracing-wasm = "0.2" 31wasm-bindgen-futures = "0.4" 32 33 34[profile.release] 35opt-level = 2 # fast and small wasm 36 37# Optimize all dependencies even in debug builds: 38[profile.dev.package."*"] 39opt-level = 2 40 41 42[patch.crates-io] 43 44# If you want to use the bleeding edge version of egui and eframe: 45# egui = { git = "https://github.com/emilk/egui", branch = "master" } 46# eframe = { git = "https://github.com/emilk/egui", branch = "master" } 47 48# If you fork https://github.com/emilk/egui you can test with: 49# egui = { path = "../egui/crates/egui" } 50# eframe = { path = "../egui/crates/eframe" } 51 52# ビルド設定 53 54#[build-dependencies] 55#cfg-if = "1.0.0" 56 57[target.'cfg(all(target_family="windows",not(target_family="wasm")))'.build-dependencies] 58windres = "0.2" 59 60[package.metadata.winres] 61OriginalFilename = "PROGRAM.EXE" 62LegalCopyright = "Copyright 著作者"
ほぼ eframe template そのまま
試したこと
all と not を使って完全にwasmの条件を排除しようとしてもダメだった。
build.rs
1#[cfg(all(target_family="windows",not(target_family="wasm")))] 2fn only_win(){ 3 extern crate windres; 4 use windres::Build; 5 Build::new().compile("assets/icon.rc").unwrap(); 6} 7 8fn main() { 9 #[cfg(all(target_family="windows",not(target_family="wasm")))] 10 only_win(); 11}
extern crate windres; を build.rs内から削除 --> 変化なし
ソースコード自体から winres に関する行を削除するとwasmビルド時でも動く。
補足情報(FW/ツールのバージョンなど)
cargo run --release だと正常に動作する。( trunk build --release の時だけ動かない)
rustup target add wasm32-unknown-unknown は実行済み。
実行環境
Windows 10 64bit
rustc & cargo 1.68.2

回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2023/04/24 03:08