Skip to content

Commit

Permalink
Use c-string literals and update trampolines (#2590)
Browse files Browse the repository at this point in the history
Rust 1.77 has stabilized c-string literals (`c"<string>"`):
https://doc.rust-lang.org/nightly/edition-guide/rust-2021/c-string-literals.html.
This PR replaces the usages of the custom c-string literal macro in the
trampoline with the new syntax.
  • Loading branch information
konstin authored Mar 21, 2024
1 parent f91ce52 commit 2375008
Show file tree
Hide file tree
Showing 10 changed files with 14 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ jobs:
working-directory: crates/uv-trampoline
run: |
rustup target add x86_64-pc-windows-msvc
rustup component add clippy rust-src --toolchain nightly-2024-01-23-x86_64-pc-windows-msvc
rustup component add clippy rust-src --toolchain nightly-2024-03-19-x86_64-pc-windows-msvc
- uses: rui314/setup-mold@v1
- uses: Swatinem/rust-cache@v2
with:
Expand Down
10 changes: 6 additions & 4 deletions crates/uv-trampoline/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,10 @@ might not realize that, and still emit references to the unwinding helper
`__CxxFrameHandler3`. And then the linker blows up because that symbol doesn't
exist.

`cargo build --release --target x86_64-pc-windows-msvc`
or `cargo build --release --target aarch64-pc-windows-msvc`
```
cargo build --release --target x86_64-pc-windows-msvc
cargo build --release --target aarch64-pc-windows-msvc
```

Hopefully in the future as `#![no_std]` develops, this will get smoother.

Expand All @@ -123,6 +125,6 @@ rustup target add aarch64-pc-windows-msvc
```

```shell
cargo +nightly xwin build --release --target x86_64-pc-windows-msvc
cargo +nightly xwin build --release --target aarch64-pc-windows-msvc
cargo +nightly-2024-03-19 xwin build --release --target x86_64-pc-windows-msvc
cargo +nightly-2024-03-19 xwin build --release --target aarch64-pc-windows-msvc
```
2 changes: 1 addition & 1 deletion crates/uv-trampoline/rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[toolchain]
channel = "nightly-2024-01-23"
channel = "nightly-2024-03-19"
10 changes: 5 additions & 5 deletions crates/uv-trampoline/src/bounce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use windows_sys::Win32::{
};

use crate::helpers::SizeOf;
use crate::{c, eprintln, format};
use crate::{eprintln, format};

const MAGIC_NUMBER: [u8; 4] = [b'U', b'V', b'U', b'V'];
const PATH_LEN_SIZE: usize = mem::size_of::<u32>();
Expand Down Expand Up @@ -438,8 +438,8 @@ fn clear_app_starting_state(child_handle: HANDLE) {
WaitForInputIdle(child_handle, INFINITE);
let hwnd = CreateWindowExA(
0,
c!("STATIC").as_ptr() as *const _,
c!("uv Python Trampoline").as_ptr() as *const _,
c"STATIC".as_ptr() as *const _,
c"uv Python Trampoline".as_ptr() as *const _,
0,
0,
0,
Expand Down Expand Up @@ -474,10 +474,10 @@ pub fn bounce(is_gui: bool) -> ! {

// (best effort) Switch to some innocuous directory so we don't hold the original
// cwd open.
if let Some(tmp) = getenv(c!("TEMP")) {
if let Some(tmp) = getenv(c"TEMP") {
SetCurrentDirectoryA(tmp.as_ptr() as *const _);
} else {
SetCurrentDirectoryA(c!("c:\\").as_ptr() as *const _);
SetCurrentDirectoryA(c"c:\\".as_ptr() as *const _);
}

// We want to ignore control-C/control-Break/logout/etc.; the same event will
Expand Down
2 changes: 1 addition & 1 deletion crates/uv-trampoline/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub(crate) fn write_diagnostic(message: &str) {
MessageBoxA(0, nul_terminated.as_ptr() as *const _, null(), 0);
return;
}
remaining = &remaining.get_unchecked(written as usize..);
remaining = remaining.get_unchecked(written as usize..);
}
}
}
8 changes: 0 additions & 8 deletions crates/uv-trampoline/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,3 @@ impl<T: Sized> SizeOf for T {
size_of::<T>() as u32
}
}

// CStr literal: c!("...")
#[macro_export]
macro_rules! c {
($s:literal) => {
core::ffi::CStr::from_bytes_with_nul_unchecked(concat!($s, "\0").as_bytes())
};
}
Binary file not shown.
Binary file modified crates/uv-trampoline/trampolines/uv-trampoline-aarch64-gui.exe
Binary file not shown.
Binary file not shown.
Binary file modified crates/uv-trampoline/trampolines/uv-trampoline-x86_64-gui.exe
Binary file not shown.

0 comments on commit 2375008

Please sign in to comment.