Skip to content
GitLab
Menu
Why GitLab
Pricing
Contact Sales
Explore
Why GitLab
Pricing
Contact Sales
Explore
Sign in
Get free trial
Changes
Page history
Update Rust
authored
Jan 26, 2024
by
Miki, Hiromitsu
Hide whitespace changes
Inline
Side-by-side
Rust.md
View page @
a54d4e8c
...
...
@@ -96,5 +96,53 @@ $3634400
### Icon for windows exe
https://stackoverflow.com/a/76500197
MinGW-w64 (例: MingW-W64-builds) の bin にパスを通しておく必要がある。
[Cargo.toml]
```
toml
[
package
]
...
build
=
"build.rs"
```
[build.rs]
```
rs
use
std
::{
env
,
fs
::{
copy
,
write
},
path
::
PathBuf
,
process
::
Command
,
};
fn
main
()
{
if
env
::
var
(
"CARGO_CFG_TARGET_OS"
)
.unwrap
()
==
"windows"
{
let
project_dir
=
PathBuf
::
from
(
env
::
var
(
"CARGO_MANIFEST_DIR"
)
.expect
(
"environment variable 'CARGO_MANIFEST_DIR' is not set"
),
);
let
out_dir_str
=
env
::
var
(
"OUT_DIR"
)
.expect
(
"environment variable 'OUT_DIR' is not set"
);
let
out_dir
=
PathBuf
::
from
(
&
out_dir_str
);
copy
(
project_dir
.join
(
"res"
)
.join
(
"icon.ico"
),
out_dir
.join
(
"icon.ico"
),
)
.expect
(
"failed to copy 'res/icon.icon' file to out directory"
);
write
(
out_dir
.join
(
"icon.rc"
),
"1 ICON icon.ico"
)
.expect
(
"failed to write 'icon.rc' file to out directory"
);
Command
::
new
(
"windres"
)
.current_dir
(
&
out_dir
)
.arg
(
"icon.rc"
)
.arg
(
"icon.lib"
)
.spawn
()
.expect
(
"failed to create 'icon.lib' using 'windres'"
);
println!
(
"cargo:rustc-link-search={}"
,
out_dir_str
);
println!
(
"cargo:rustc-link-lib=icon"
);
}
}
```
参考:
\
https://stackoverflow.com/a/76500197