Changes
Page history
Update Rust
authored
Jan 27, 2024
by
Miki, Hiromitsu
Show whitespace changes
Inline
Side-by-side
Rust.md
View page @
d4600fd2
...
@@ -104,46 +104,4 @@ $3634400
...
@@ -104,46 +104,4 @@ $3634400
### Icon for windows exe (GNU)
### Icon for windows exe (GNU)
GNU 版のバイナリ (GNU ABI) の場合、windres.exe を使用してリソースを含むライブラリを作成、これとリンクすることでアイコンを埋め込むことができる。
\
$3643327
以下手順を行う前に、MinGW-w64 (例: MinGW-W64-builds) の bin にパスを通しておく必要がある。
MSVC 版のバイナリ (MSVC ABI) の場合はやり方が異なり、ツールとして Windows SDK の rc.exe を使用する。
[build.rs]
```
rs
use
std
::
path
::
PathBuf
;
use
std
::
process
::
Command
;
fn
main
()
{
if
std
::
env
::
var
(
"CARGO_CFG_TARGET_OS"
)
.unwrap
()
==
"windows"
{
let
project_dir
=
PathBuf
::
from
(
std
::
env
::
var
(
"CARGO_MANIFEST_DIR"
)
.expect
(
"environment variable 'CARGO_MANIFEST_DIR' is not set"
),
);
let
out_dir_str
=
std
::
env
::
var
(
"OUT_DIR"
)
.expect
(
"environment variable 'OUT_DIR' is not set"
);
let
out_dir
=
PathBuf
::
from
(
&
out_dir_str
);
std
::
fs
::
copy
(
project_dir
.join
(
"res"
)
.join
(
"icon.ico"
),
out_dir
.join
(
"icon.ico"
),
)
.expect
(
"failed to copy 'res/icon.icon' file to out directory"
);
std
::
fs
::
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