diff options
author | Divy Srivastava <dj.srivastava23@gmail.com> | 2024-08-14 21:42:23 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-15 10:12:23 +0530 |
commit | 7ca95fc999f22cb0eb312e02f8c40d7589b35b7e (patch) | |
tree | 9d4b27eb8f180aafba40c869db6acf20ea5f5423 /cli/standalone | |
parent | e92a05b5518e5fd30559c96c5990b08657bbc3e4 (diff) |
feat: `deno compile --icon <ico>` (#25039)
Add `--icon` flag to set deno compile'd executable icon on Windows.
```
deno compile --icon icon.ico game.tsx
```
Depends on https://github.com/denoland/sui/pull/24
<img width="447" alt="image"
src="https://github.com/user-attachments/assets/7f6f3aa0-6872-4975-ae9d-06701b7684b8">
Closes https://github.com/denoland/deno/issues/8912
Diffstat (limited to 'cli/standalone')
-rw-r--r-- | cli/standalone/binary.rs | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/cli/standalone/binary.rs b/cli/standalone/binary.rs index 78978cefc..9d6d5262e 100644 --- a/cli/standalone/binary.rs +++ b/cli/standalone/binary.rs @@ -187,10 +187,19 @@ fn write_binary_bytes( let target = compile_flags.resolve_target(); if target.contains("linux") { - libsui::Elf::new(&original_bin).append(&writer, &mut file_writer)?; + libsui::Elf::new(&original_bin).append( + "d3n0l4nd", + &writer, + &mut file_writer, + )?; } else if target.contains("windows") { - libsui::PortableExecutable::from(&original_bin)? - .write_resource("d3n0l4nd", writer)? + let mut pe = libsui::PortableExecutable::from(&original_bin)?; + if let Some(icon) = compile_flags.icon.as_ref() { + let icon = std::fs::read(icon)?; + pe = pe.set_icon(&icon)?; + } + + pe.write_resource("d3n0l4nd", writer)? .build(&mut file_writer)?; } else if target.contains("darwin") { libsui::Macho::from(original_bin)? @@ -370,6 +379,15 @@ impl<'a> DenoCompileBinaryWriter<'a> { } set_windows_binary_to_gui(&mut original_binary)?; } + if compile_flags.icon.is_some() { + let target = compile_flags.resolve_target(); + if !target.contains("windows") { + bail!( + "The `--icon` flag is only available when targeting Windows (current: {})", + target, + ) + } + } self.write_standalone_binary( writer, original_binary, |