mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
Fix cargo build -p libservo
on macOS 13 by running Python via uv
(#37290)
The correct way to run Python when building Servo is `uv run python`, unless we are running as a descendant of `uv run python`. In that case, we can use either `uv run python` or `python` (uv does not provide a `python3` on Windows \*). \* for the astute reader, yes, this causes problems for mozjs, which only tries `python3` unless PYTHON3=python :))) Testing: tested manually on macOS 13 (see below), and will be tested in CI Fixes: #37289  Signed-off-by: Delan Azabani <dazabani@igalia.com>
This commit is contained in:
parent
ba33fd1318
commit
c7a215faba
2 changed files with 25 additions and 87 deletions
|
@ -27,7 +27,7 @@ fn main() {
|
||||||
println!("cargo::rerun-if-changed=../../third_party/WebIDL/WebIDL.py");
|
println!("cargo::rerun-if-changed=../../third_party/WebIDL/WebIDL.py");
|
||||||
// NB: We aren't handling changes in `third_party/ply` here.
|
// NB: We aren't handling changes in `third_party/ply` here.
|
||||||
|
|
||||||
let status = Command::new(find_python())
|
let status = find_python()
|
||||||
.arg("codegen/run.py")
|
.arg("codegen/run.py")
|
||||||
.arg(&css_properties_json)
|
.arg(&css_properties_json)
|
||||||
.arg(&out_dir)
|
.arg(&out_dir)
|
||||||
|
@ -78,55 +78,20 @@ impl phf_shared::PhfHash for Bytes<'_> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Tries to find a suitable python
|
/// Tries to find a suitable python, which in Servo is always `uv run python` unless we are running
|
||||||
|
/// as a descendant of `uv run python`. In that case, we can use either `uv run python` or `python`
|
||||||
|
/// (uv does not provide a `python3` on Windows).
|
||||||
///
|
///
|
||||||
/// Algorithm
|
/// More details: <https://book.servo.org/hacking/setting-up-your-environment.html#check-tools>
|
||||||
/// 1. Trying to find python3/python in $VIRTUAL_ENV (this should be from Servo's venv)
|
|
||||||
/// 2. Checking PYTHON3 (set by mach)
|
|
||||||
/// 3. Falling back to the system installation.
|
|
||||||
///
|
///
|
||||||
/// Note: This function should be kept in sync with the version in `components/servo/build.rs`
|
/// Note: This function should be kept in sync with the version in `components/script/build.rs`
|
||||||
fn find_python() -> PathBuf {
|
fn find_python() -> Command {
|
||||||
let mut candidates = vec![];
|
let mut command = Command::new("uv");
|
||||||
if let Some(venv) = env::var_os("VIRTUAL_ENV") {
|
command.args(["run", "python"]);
|
||||||
let bin_directory = PathBuf::from(venv).join("bin");
|
|
||||||
|
|
||||||
let python3 = bin_directory.join("python3");
|
if command.output().is_ok_and(|out| out.status.success()) {
|
||||||
if python3.exists() {
|
return command;
|
||||||
candidates.push(python3);
|
|
||||||
}
|
|
||||||
let python = bin_directory.join("python");
|
|
||||||
if python.exists() {
|
|
||||||
candidates.push(python);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
if let Some(python3) = env::var_os("PYTHON3") {
|
|
||||||
let python3 = PathBuf::from(python3);
|
|
||||||
if python3.exists() {
|
|
||||||
candidates.push(python3);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let system_python = ["python3", "python"].map(PathBuf::from);
|
panic!("Can't find python (tried `{command:?}`)! Is uv installed and in PATH?")
|
||||||
candidates.extend_from_slice(&system_python);
|
|
||||||
|
|
||||||
for name in &candidates {
|
|
||||||
// Command::new() allows us to omit the `.exe` suffix on windows
|
|
||||||
if Command::new(name)
|
|
||||||
.arg("--version")
|
|
||||||
.output()
|
|
||||||
.is_ok_and(|out| out.status.success())
|
|
||||||
{
|
|
||||||
return name.to_owned();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
let candidates = candidates
|
|
||||||
.into_iter()
|
|
||||||
.map(|c| c.into_os_string())
|
|
||||||
.collect::<Vec<_>>();
|
|
||||||
panic!(
|
|
||||||
"Can't find python (tried {:?})! Try enabling Servo's Python venv, \
|
|
||||||
setting the PYTHON3 env var or adding python3 to PATH.",
|
|
||||||
candidates.join(", ".as_ref())
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::Path;
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
use std::{env, fs};
|
use std::{env, fs};
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ fn main() {
|
||||||
if cfg!(feature = "media-gstreamer") {
|
if cfg!(feature = "media-gstreamer") {
|
||||||
println!("cargo:rerun-if-changed=../../python/servo/gstreamer.py");
|
println!("cargo:rerun-if-changed=../../python/servo/gstreamer.py");
|
||||||
|
|
||||||
let output = Command::new(find_python())
|
let output = find_python()
|
||||||
.arg("../../python/servo/gstreamer.py")
|
.arg("../../python/servo/gstreamer.py")
|
||||||
.arg(std::env::var_os("TARGET").unwrap())
|
.arg(std::env::var_os("TARGET").unwrap())
|
||||||
.output()
|
.output()
|
||||||
|
@ -25,47 +25,20 @@ fn main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Tries to find a suitable python
|
/// Tries to find a suitable python, which in Servo is always `uv run python` unless we are running
|
||||||
|
/// as a descendant of `uv run python`. In that case, we can use either `uv run python` or `python`
|
||||||
|
/// (uv does not provide a `python3` on Windows).
|
||||||
///
|
///
|
||||||
/// Algorithm
|
/// More details: <https://book.servo.org/hacking/setting-up-your-environment.html#check-tools>
|
||||||
/// 1. Trying to find python3/python in $VIRTUAL_ENV (this should be from servos venv)
|
|
||||||
/// 2. Checking PYTHON3 (set by mach)
|
|
||||||
/// 3. Falling back to the system installation.
|
|
||||||
///
|
///
|
||||||
/// Note: This function should be kept in sync with the version in `components/script/build.rs`
|
/// Note: This function should be kept in sync with the version in `components/script/build.rs`
|
||||||
fn find_python() -> PathBuf {
|
fn find_python() -> Command {
|
||||||
let mut candidates = vec![];
|
let mut command = Command::new("uv");
|
||||||
if let Some(venv) = env::var_os("VIRTUAL_ENV") {
|
command.args(["run", "python"]);
|
||||||
// See: https://docs.python.org/3/library/venv.html#how-venvs-work
|
|
||||||
let bin_dir = if cfg!(windows) { "Scripts" } else { "bin" };
|
if command.output().is_ok_and(|out| out.status.success()) {
|
||||||
let bin_directory = PathBuf::from(venv).join(bin_dir);
|
return command;
|
||||||
candidates.push(bin_directory.join("python3"));
|
|
||||||
candidates.push(bin_directory.join("python"));
|
|
||||||
}
|
|
||||||
if let Some(python3) = env::var_os("PYTHON3") {
|
|
||||||
candidates.push(PathBuf::from(python3));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let system_python = ["python3", "python"].map(PathBuf::from);
|
panic!("Can't find python (tried `{command:?}`)! Is uv installed and in PATH?")
|
||||||
candidates.extend_from_slice(&system_python);
|
|
||||||
|
|
||||||
for name in &candidates {
|
|
||||||
// Command::new() allows us to omit the `.exe` suffix on windows
|
|
||||||
if Command::new(name)
|
|
||||||
.arg("--version")
|
|
||||||
.output()
|
|
||||||
.is_ok_and(|out| out.status.success())
|
|
||||||
{
|
|
||||||
return name.to_owned();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
let candidates = candidates
|
|
||||||
.into_iter()
|
|
||||||
.map(|c| c.into_os_string())
|
|
||||||
.collect::<Vec<_>>();
|
|
||||||
panic!(
|
|
||||||
"Can't find python (tried {:?})! Try enabling Servo's Python venv, \
|
|
||||||
setting the PYTHON3 env var or adding python3 to PATH.",
|
|
||||||
candidates.join(", ".as_ref())
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue