Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Release Notes

## 0.13.0

This release brings support for `gui-scripts` and `pythonw.exe` on Windows.

## 0.12.6

This release fixes generation of `--sh-boot` headers on Windows.
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cargo-features = ["profile-rustflags"]

[package]
name = "pexrc"
version = "0.12.6"
version = "0.13.0"
edition = { workspace = true }
publish = false

Expand Down
90 changes: 88 additions & 2 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ fn main() -> anyhow::Result<()> {
&[]
};

let python_proxyw_options = [Cow::Borrowed("--features"), Cow::Borrowed("windows")];

println!("cargo::rerun-if-env-changed=PEXRC_TARGETS");
if all_targets {
println!("cargo::rerun-if-changed=rust-toolchain");
Expand All @@ -202,6 +204,8 @@ fn main() -> anyhow::Result<()> {
tgt_arg,
"--package",
"python-proxy",
"--bin",
"python-proxy",
],
&[],
embeds_configuration.profile,
Expand All @@ -211,6 +215,33 @@ fn main() -> anyhow::Result<()> {
.map(BuildTarget::zigbuild_target),
python_proxy_optimizations,
)?;
custom_cargo_build(
&cargo,
&[
"zigbuild",
"--target-dir",
tgt_arg,
"--package",
"python-proxy",
"--bin",
"python-proxyw",
],
&python_proxyw_options,
embeds_configuration.profile,
&found_tools,
targets
.iter_zigbuild_targets()
.filter_map(|target| {
if target.is_windows() {
Some(target.zigbuild_target())
} else {
None
}
})
.collect::<Vec<_>>()
.into_iter(),
python_proxy_optimizations,
)?;

custom_cargo_build(
&cargo,
Expand All @@ -237,24 +268,45 @@ fn main() -> anyhow::Result<()> {
tgt_arg,
"--package",
"python-proxy",
"--bin",
"python-proxy",
],
&[],
embeds_configuration.profile,
&found_tools,
targets.iter_xwin_targets().map(BuildTarget::as_str),
python_proxy_optimizations,
)?;
custom_cargo_build(
&cargo,
&[
"xwin",
"build",
"--target-dir",
tgt_arg,
"--package",
"python-proxy",
"--bin",
"python-proxyw",
],
&python_proxyw_options,
embeds_configuration.profile,
&found_tools,
targets.iter_xwin_targets().map(BuildTarget::as_str),
python_proxy_optimizations,
)?;
collect_embeds(&targets, &tgt_path, embeds_configuration, &embeds_dir, true)
} else {
let target = env::var("TARGET")?;
let targets = ClassifiedTargets::parse([target.as_str()].into_iter(), &glibc);
let current_target = BuildTarget::current(&glibc);
custom_cargo_build(
&cargo,
&["build", "--target-dir", tgt_arg, "--package", "clib"],
optional_clib_args,
embeds_configuration.profile,
&found_tools,
[BuildTarget::current(&glibc).as_str()].into_iter(),
[current_target.as_str()].into_iter(),
clib_optimizations,
)?;
custom_cargo_build(
Expand All @@ -265,13 +317,34 @@ fn main() -> anyhow::Result<()> {
tgt_arg,
"--package",
"python-proxy",
"--bin",
"python-proxy",
],
&[],
embeds_configuration.profile,
&found_tools,
[BuildTarget::current(&glibc).as_str()].into_iter(),
[current_target.as_str()].into_iter(),
python_proxy_optimizations,
)?;
if current_target.is_windows() {
custom_cargo_build(
&cargo,
&[
"build",
"--target-dir",
tgt_arg,
"--package",
"python-proxy",
"--bin",
"python-proxyw",
],
&python_proxyw_options,
embeds_configuration.profile,
&found_tools,
[current_target.as_str()].into_iter(),
python_proxy_optimizations,
)?;
}
collect_embeds(&targets, &tgt_path, embeds_configuration, &embeds_dir, true)
}
}
Expand Down Expand Up @@ -368,6 +441,19 @@ fn collect_embeds<'a>(
&target_name,
compress,
)?;
if target.is_windows() {
let python_proxy_name = target.binary_name("python-proxyw", None);
let target_name = target.fully_qualified_binary_name("python-proxyw", None)?;
collect_embed(
&python_proxy_name,
&proxies_dir,
embeds_configuration,
target,
target_dir,
&target_name,
compress,
)?;
}
}
Ok(())
}
Expand Down
4 changes: 4 additions & 0 deletions crates/build-system/src/rust_toolchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ impl<'a> BuildTarget<'a> {
}
}

pub fn is_windows(&self) -> bool {
matches!(self.target, Target::Windows(_))
}

pub fn as_str(&self) -> &str {
self.target.as_str()
}
Expand Down
6 changes: 4 additions & 2 deletions crates/pexrs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ struct PythonProxyLinker<'a>(&'a Pex<'a>);

impl<'a> Linker for PythonProxyLinker<'a> {
#[cfg(unix)]
fn link(&self, dest: &Path, interpreter: Option<&Path>) -> anyhow::Result<()> {
fn link(&self, dest: &Path, interpreter: Option<&Path>, is_gui: bool) -> anyhow::Result<()> {
let file_name = dest.file_name().ok_or_else(|| {
anyhow!(
"The destination for the python-proxy doesn't have a file name: {path}",
Expand Down Expand Up @@ -54,6 +54,7 @@ impl<'a> Linker for PythonProxyLinker<'a> {
venv_python_file_name.as_ref(),
file.into_file(),
None,
is_gui,
)
})?;

Expand All @@ -72,13 +73,14 @@ impl<'a> Linker for PythonProxyLinker<'a> {
}

#[cfg(windows)]
fn link(&self, dest: &Path, interpreter: Option<&Path>) -> anyhow::Result<()> {
fn link(&self, dest: &Path, interpreter: Option<&Path>, is_gui: bool) -> anyhow::Result<()> {
python_proxy::create(
ProxySource::Pex(self.0),
interpreter
.ok_or_else(|| anyhow!("Windows venvs require an interpreter to link to."))?,
fs::File::create(dest)?.into_file(),
None,
is_gui,
)
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/platform/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ impl<'a> Display for PosixPath<'a> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
for (idx, component) in self.0.components().enumerate() {
if idx > 0 {
f.write_str("/")?;
f.write_char('/')?;
}
match component {
Component::CurDir => f.write_char('.')?,
Expand Down
12 changes: 12 additions & 0 deletions crates/python-proxy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,22 @@ name = "python-proxy"
edition = { workspace = true }
publish = false

[[bin]]
name = "python-proxy"
path = "src/bin/main.rs"

[[bin]]
name = "python-proxyw"
path = "src/bin/mainw.rs"
required-features = ["windows"]

[dependencies]
anyhow = { workspace = true }
cache = { path = "../cache" }
pex = { path = "../pex" }
platform = { path = "../platform" }
target = { path = "../target" }
zip = { workspace = true }

[features]
windows = []
56 changes: 56 additions & 0 deletions crates/python-proxy/src/bin/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright 2026 Pex project contributors.
// SPDX-License-Identifier: Apache-2.0

#![deny(clippy::all)]

use std::io::ErrorKind;
use std::path::PathBuf;
use std::process::exit;
use std::{env, io};

use python_proxy::read_proxy;

#[cfg(unix)]
fn proxy_path() -> io::Result<PathBuf> {
env::args()
.next()
.ok_or_else(|| {
io::Error::new(
ErrorKind::NotFound,
"No argv0 was present; python-proxy cannot run.",
)
})
.map(PathBuf::from)
}

#[cfg(windows)]
fn proxy_path() -> io::Result<PathBuf> {
env::current_exe()
}

fn main() {
let python_proxy = match proxy_path().and_then(read_proxy) {
Ok(python) => python,
Err(err) => {
eprintln!("Failed to determine python executable path: {err}");
exit(1);
}
};
let (mut command, pexrc_cache_read_lock) = match python_proxy.prepare_command() {
Ok(proxy) => proxy,
Err(err) => {
eprintln!("Failed to prepare python proxy command: {err}");
exit(1);
}
};
match platform::exec(&mut command, &[pexrc_cache_read_lock]) {
Ok(status) => exit(status),
Err(err) => {
eprintln!(
"Failed to spawn {python}: {err}",
python = python_proxy.target.display()
);
exit(1);
}
}
}
55 changes: 55 additions & 0 deletions crates/python-proxy/src/bin/mainw.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright 2026 Pex project contributors.
// SPDX-License-Identifier: Apache-2.0

#![cfg(windows)]
#![deny(clippy::all)]
#![windows_subsystem = "windows"]

use std::env;
use std::os::windows::process::CommandExt;
use std::process::{Child, exit};

use python_proxy::{PythonProxy, read_proxy};

// See: https://learn.microsoft.com/en-us/windows/win32/procthread/process-creation-flags
const DETACHED_PROCESS: u32 = 0x00000008;

fn main() {
let python_proxy = match env::current_exe().and_then(read_proxy) {
Ok(python) => python,
Err(err) => {
eprintln!("Failed to determine python executable path: {err}");
exit(1);
}
};

let (mut command, _pexrc_cache_read_lock) = match python_proxy.prepare_command() {
Ok(proxy) => proxy,
Err(err) => {
eprintln!("Failed to prepare python proxy command: {err}");
exit(1);
}
};
command.creation_flags(DETACHED_PROCESS);

match command.spawn() {
Ok(mut child) => match child.wait() {
Ok(exit_status) => {
if !exit_status.success() {
exit(exit_status.code().unwrap_or(1))
}
}
Err(err) => {
eprintln!(
"Failed to wait for python proxy child process {id} to complete: {err}",
id = child.id()
);
exit(1)
}
},
Err(err) => {
eprintln!("{err}");
exit(1)
}
}
}
Loading