Skip to content

Commit caf49f8

Browse files
paveldikovsamypr100zanieb
authored
Use .rcdata to store trampoline type + path to python binary (#15068)
`.rsrc` is the idiomatic way of storing metadata and non-code resources in PE binaries. This should make the resulting binaries more robust as they are no longer dependent on the exact location of a certain magic number. Addresses: #15022 ## Test Plan Existing integration test for `uv-trampoline-builder` + addition to ensure robustness to code signing. --------- Co-authored-by: samypr100 <[email protected]> Co-authored-by: Zanie Blue <[email protected]>
1 parent 1b7faaf commit caf49f8

File tree

16 files changed

+569
-374
lines changed

16 files changed

+569
-374
lines changed

Cargo.lock

Lines changed: 75 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ uuid = { version = "1.16.0" }
196196
version-ranges = { git = "https://github.com/astral-sh/pubgrub", rev = "d8efd77673c9a90792da9da31b6c0da7ea8a324b" }
197197
walkdir = { version = "2.5.0" }
198198
which = { version = "8.0.0", features = ["regex"] }
199-
windows = { version = "0.59.0", features = ["Win32_Globalization", "Win32_Security", "Win32_System_Console", "Win32_System_Kernel", "Win32_System_Diagnostics_Debug", "Win32_Storage_FileSystem", "Win32_System_Registry", "Win32_System_IO", "Win32_System_Ioctl"] }
199+
windows = { version = "0.59.0", features = ["std", "Win32_Globalization", "Win32_System_LibraryLoader", "Win32_System_Console", "Win32_System_Kernel", "Win32_System_Diagnostics_Debug", "Win32_Storage_FileSystem", "Win32_Security", "Win32_System_Registry", "Win32_System_IO", "Win32_System_Ioctl"] }
200200
windows-registry = { version = "0.5.0" }
201201
wiremock = { version = "0.6.4" }
202202
wmi = { version = "0.16.0", default-features = false }
@@ -216,6 +216,7 @@ hyper-util = { version = "0.1.8", features = ["tokio"] }
216216
ignore = { version = "0.4.23" }
217217
insta = { version = "1.40.0", features = ["json", "filters", "redactions"] }
218218
predicates = { version = "3.1.2" }
219+
rcgen = { version = "0.14.5", features = ["crypto", "pem", "ring"], default-features = false }
219220
similar = { version = "2.6.0" }
220221
temp-env = { version = "0.3.6" }
221222
test-case = { version = "3.3.1" }

crates/uv-python/src/managed.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use std::str::FromStr;
1010

1111
use fs_err as fs;
1212
use itertools::Itertools;
13-
use same_file::is_same_file;
1413
use thiserror::Error;
1514
use tracing::{debug, warn};
1615
use uv_preview::{Preview, PreviewFeatures};
@@ -22,7 +21,7 @@ use uv_platform::{Error as PlatformError, Os};
2221
use uv_platform::{LibcDetectionError, Platform};
2322
use uv_state::{StateBucket, StateStore};
2423
use uv_static::EnvVars;
25-
use uv_trampoline_builder::{Launcher, windows_python_launcher};
24+
use uv_trampoline_builder::{Launcher, LauncherKind};
2625

2726
use crate::downloads::{Error as DownloadError, ManagedPythonDownload};
2827
use crate::implementation::{
@@ -649,12 +648,12 @@ impl ManagedPythonInstallation {
649648
/// [`create_bin_link`].
650649
pub fn is_bin_link(&self, path: &Path) -> bool {
651650
if cfg!(unix) {
652-
is_same_file(path, self.executable(false)).unwrap_or_default()
651+
same_file::is_same_file(path, self.executable(false)).unwrap_or_default()
653652
} else if cfg!(windows) {
654653
let Some(launcher) = Launcher::try_from_path(path).unwrap_or_default() else {
655654
return false;
656655
};
657-
if !matches!(launcher.kind, uv_trampoline_builder::LauncherKind::Python) {
656+
if !matches!(launcher.kind, LauncherKind::Python) {
658657
return false;
659658
}
660659
// We canonicalize the target path of the launcher in case it includes a minor version
@@ -922,6 +921,8 @@ pub fn create_link_to_executable(link: &Path, executable: &Path) -> Result<(), E
922921
}),
923922
}
924923
} else if cfg!(windows) {
924+
use uv_trampoline_builder::windows_python_launcher;
925+
925926
// TODO(zanieb): Install GUI launchers as well
926927
let launcher = windows_python_launcher(executable, false)?;
927928

@@ -938,7 +939,7 @@ pub fn create_link_to_executable(link: &Path, executable: &Path) -> Result<(), E
938939
})
939940
}
940941
} else {
941-
unimplemented!("Only Windows and Unix systems are supported.")
942+
unimplemented!("Only Windows and Unix are supported.")
942943
}
943944
}
944945

crates/uv-trampoline-builder/Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,18 @@ workspace = true
2323

2424
[dependencies]
2525
uv-fs = { workspace = true }
26-
2726
fs-err = {workspace = true }
27+
tempfile = { workspace = true }
2828
thiserror = { workspace = true }
2929
zip = { workspace = true }
3030

31+
[target.'cfg(target_os = "windows")'.dependencies]
32+
windows = { workspace = true }
33+
3134
[dev-dependencies]
3235
assert_cmd = { workspace = true }
3336
assert_fs = { workspace = true }
3437
anyhow = { workspace = true }
3538
fs-err = { workspace = true }
39+
rcgen = { workspace = true }
3640
which = { workspace = true }

0 commit comments

Comments
 (0)