Skip to content

Commit 8b62409

Browse files
authored
fix: build scripts for windows (#123)
* fix: build scripts for windows * test: add tests * fix: taplo
1 parent 9b38e0f commit 8b62409

12 files changed

+187
-61
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ minijinja = "2.7.0"
1919
parking_lot = "0.12.3"
2020
reqwest = "0.12.12"
2121
reqwest-middleware = "0.4.0"
22+
rstest = "0.25.0"
2223
serde = "1.0"
2324
serde_yaml = "0.9"
2425
serde_json = "1.0"

crates/pixi-build-rust/Cargo.toml

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,45 +6,22 @@ edition.workspace = true
66
[dependencies]
77
async-trait = { workspace = true }
88
chrono = { workspace = true }
9-
clap = { workspace = true, features = ["derive", "env"] }
10-
clap-verbosity-flag = { workspace = true }
11-
fs-err = { workspace = true }
12-
indexmap = { workspace = true }
13-
itertools = { workspace = true }
14-
log = { workspace = true }
159
miette = { workspace = true }
16-
minijinja = { workspace = true }
17-
parking_lot = { workspace = true }
10+
minijinja = { workspace = true, features = ["json"] }
1811
rattler_conda_types = { workspace = true }
1912
rattler_package_streaming = { workspace = true }
20-
rattler_virtual_packages = { workspace = true }
2113
rattler-build = { workspace = true }
22-
reqwest = { workspace = true }
23-
reqwest-middleware = { workspace = true }
2414
serde = { workspace = true, features = ["derive"] }
25-
serde_yaml = { workspace = true }
2615
serde_json = { workspace = true }
27-
toml_edit = { workspace = true }
2816
tempfile = { workspace = true }
2917
tokio = { workspace = true, features = ["macros"] }
30-
tracing-subscriber = { workspace = true }
31-
url = { workspace = true }
32-
pyproject-toml = { workspace = true }
33-
dirs = { workspace = true }
34-
pathdiff = { workspace = true }
3518

3619
pixi-build-backend = { workspace = true }
3720

3821
pixi_build_types = { workspace = true }
39-
pixi_consts = { workspace = true }
4022
pixi_manifest = { workspace = true }
41-
pixi_spec = { workspace = true }
4223
pixi_build_type_conversions = { workspace = true }
4324

44-
jsonrpc-stdio-server = { workspace = true }
45-
jsonrpc-http-server = { workspace = true }
46-
jsonrpc-core = { workspace = true }
47-
4825
[dev-dependencies]
4926
insta = { version = "1.42.1", features = ["yaml", "redactions", "filters"] }
50-
toml_edit = { version = "0.22.24" }
27+
rstest = { workspace = true }
Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
1-
{% if export_openssl -%}
2-
export OPENSSL_DIR="$PREFIX"
3-
{% endif %}
1+
{% macro env(key) -%}
2+
{%- if is_bash %}{{ "$" ~key }}{% else %}{{ "%" ~ key ~ "%" }}{% endif -%}
3+
{% endmacro -%}
4+
{%- macro export(key, value) -%}
5+
{%- if is_bash -%}
6+
export {{ key }}={{ value }}
7+
{%- else -%}
8+
SET {{ key }}={{ value }}
9+
{%- endif -%}
10+
{%- endmacro -%}
411

5-
{% if has_sccache -%}
6-
export RUSTC_WRAPPER="sccache"
7-
{% endif %}
12+
{%- if has_openssl %}
13+
{{ export("OPENSSL_DIR", env("PREFIX")|tojson) }}
14+
{%- endif %}
15+
{%- if has_sccache %}
16+
{{ export("RUSTC_WRAPPER", "sccache") }}
17+
{%- endif %}
818

9-
cargo install --locked --root $PREFIX --path {{ source_dir }} --no-track {{ extra_args | join(" ") }} --force
19+
cargo install --locked --root "{{ env("PREFIX") }}" --path {{ source_dir }} --no-track {{ extra_args | join(" ") }} --force
20+
{%- if not is_bash %}
21+
if errorlevel 1 exit 1
22+
{%- endif %}
1023

11-
{% if has_sccache -%}
12-
sccache --show-stats
13-
{% endif %}
24+
{% if has_sccache %}sccache --show-stats{% endif %}

crates/pixi-build-rust/src/build_script.rs

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,20 @@ use serde::Serialize;
33

44
#[derive(Serialize)]
55
pub struct BuildScriptContext {
6+
/// The location of the source
67
pub source_dir: String,
8+
9+
/// Any additional args to pass to `cargo`
710
pub extra_args: Vec<String>,
8-
pub export_openssl: bool,
11+
12+
/// True if `openssl` is part of the build environment
13+
pub has_openssl: bool,
14+
15+
/// True if `sccache` is available.
916
pub has_sccache: bool,
17+
18+
/// The platform that is running the build.
19+
pub is_bash: bool,
1020
}
1121

1222
impl BuildScriptContext {
@@ -19,3 +29,62 @@ impl BuildScriptContext {
1929
rendered.lines().map(|s| s.to_string()).collect()
2030
}
2131
}
32+
33+
#[cfg(test)]
34+
mod test {
35+
use rstest::*;
36+
37+
#[rstest]
38+
fn test_build_script(#[values(true, false)] is_bash: bool) {
39+
let context = super::BuildScriptContext {
40+
source_dir: String::from("my-prefix-dir"),
41+
extra_args: vec![],
42+
has_openssl: false,
43+
has_sccache: false,
44+
is_bash,
45+
};
46+
let script = context.render();
47+
48+
let mut settings = insta::Settings::clone_current();
49+
settings.set_snapshot_suffix(if is_bash { "bash" } else { "cmdexe" });
50+
settings.bind(|| {
51+
insta::assert_snapshot!(script.join("\n"));
52+
});
53+
}
54+
55+
#[rstest]
56+
fn test_sccache(#[values(true, false)] is_bash: bool) {
57+
let context = super::BuildScriptContext {
58+
source_dir: String::from("my-prefix-dir"),
59+
extra_args: vec![],
60+
has_openssl: false,
61+
has_sccache: true,
62+
is_bash,
63+
};
64+
let script = context.render();
65+
66+
let mut settings = insta::Settings::clone_current();
67+
settings.set_snapshot_suffix(if is_bash { "bash" } else { "cmdexe" });
68+
settings.bind(|| {
69+
insta::assert_snapshot!(script.join("\n"));
70+
});
71+
}
72+
73+
#[rstest]
74+
fn test_openssl(#[values(true, false)] is_bash: bool) {
75+
let context = super::BuildScriptContext {
76+
source_dir: String::from("my-prefix-dir"),
77+
extra_args: vec![],
78+
has_openssl: true,
79+
has_sccache: false,
80+
is_bash,
81+
};
82+
let script = context.render();
83+
84+
let mut settings = insta::Settings::clone_current();
85+
settings.set_snapshot_suffix(if is_bash { "bash" } else { "cmdexe" });
86+
settings.bind(|| {
87+
insta::assert_snapshot!(script.join("\n"));
88+
});
89+
}
90+
}

crates/pixi-build-rust/src/rust.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ impl<P: ProjectModel> RustBuildBackend<P> {
9696
let (has_sccache, requirements) =
9797
self.requirements(host_platform, channel_config, variant)?;
9898

99-
let export_openssl = self
99+
let has_openssl = self
100100
.project_model
101101
.dependencies(Some(host_platform))
102102
.contains(&"openssl".into());
@@ -106,8 +106,9 @@ impl<P: ProjectModel> RustBuildBackend<P> {
106106
let build_script = BuildScriptContext {
107107
source_dir: self.manifest_root.display().to_string(),
108108
extra_args: self.config.extra_args.clone(),
109-
export_openssl,
109+
has_openssl,
110110
has_sccache,
111+
is_bash: !Platform::current().is_windows(),
111112
}
112113
.render();
113114

@@ -253,7 +254,7 @@ mod tests {
253254
".requirements.build[0]" => insta::dynamic_redaction(|value, _path| {
254255
// assert that the value looks like a uuid here
255256
assert!(value.as_str().unwrap().contains("rust"));
256-
}),
257+
}),
257258
});
258259
}
259260
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
source: crates/pixi-build-rust/src/build_script.rs
3+
expression: "script.join(\"\\n\")"
4+
---
5+
cargo install --locked --root "$PREFIX" --path my-prefix-dir --no-track --force
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
source: crates/pixi-build-rust/src/build_script.rs
3+
expression: "script.join(\"\\n\")"
4+
---
5+
cargo install --locked --root "%PREFIX%" --path my-prefix-dir --no-track --force
6+
if errorlevel 1 exit 1
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
source: crates/pixi-build-rust/src/build_script.rs
3+
expression: "script.join(\"\\n\")"
4+
---
5+
export OPENSSL_DIR="$PREFIX"
6+
7+
cargo install --locked --root "$PREFIX" --path my-prefix-dir --no-track --force
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
source: crates/pixi-build-rust/src/build_script.rs
3+
expression: "script.join(\"\\n\")"
4+
---
5+
SET OPENSSL_DIR="%PREFIX%"
6+
7+
cargo install --locked --root "%PREFIX%" --path my-prefix-dir --no-track --force
8+
if errorlevel 1 exit 1

0 commit comments

Comments
 (0)