Use c-string literals and update trampolines (#2590)

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.
This commit is contained in:
konsti 2024-03-21 16:36:00 +01:00 committed by GitHub
parent f91ce521c5
commit 2375008cc1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 14 additions and 20 deletions

View file

@ -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:

View file

@ -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.
@ -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
```

View file

@ -1,2 +1,2 @@
[toolchain]
channel = "nightly-2024-01-23"
channel = "nightly-2024-03-19"

View file

@ -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>();
@ -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,
@ -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

View file

@ -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..);
}
}
}

View file

@ -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())
};
}