Skip to content

Commit 0d67097

Browse files
authored
feat: mojo build backend (#251)
1 parent 9dd9709 commit 0d67097

16 files changed

+1614
-3
lines changed

Cargo.lock

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

crates/pixi-build-mojo/Cargo.toml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
[package]
2+
name = "pixi-build-mojo"
3+
version = "0.1.0"
4+
edition.workspace = true
5+
6+
[profile.dev.package]
7+
insta.opt-level = 3
8+
similar.opt-level = 3
9+
10+
[dependencies]
11+
async-trait = { workspace = true }
12+
chrono = { workspace = true }
13+
indexmap = { workspace = true }
14+
miette = { workspace = true }
15+
minijinja = { workspace = true }
16+
rattler_conda_types = { workspace = true }
17+
rattler_package_streaming = { workspace = true }
18+
rattler-build = { workspace = true }
19+
serde = { workspace = true, features = ["derive"] }
20+
serde_json = { workspace = true }
21+
tempfile = { workspace = true }
22+
tokio = { workspace = true, features = ["macros"] }
23+
24+
pixi-build-backend = { workspace = true }
25+
26+
pixi_build_types = { workspace = true }
27+
pixi_manifest = { workspace = true }
28+
pixi_build_type_conversions = { workspace = true }
29+
30+
recipe-stage0 = { workspace = true }
31+
32+
[dev-dependencies]
33+
insta = { version = "1.42.1", features = ["yaml", "redactions", "filters"] }
34+
rstest = "0.23"
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{%- set is_cmd_exe = build_platform == "windows" -%}
2+
{%- macro env(key) -%}
3+
{%- if is_cmd_exe %}{{ "%" ~ key ~ "%" }}{% else %}{{ "$" ~key }}{% endif -%}
4+
{% endmacro -%}
5+
6+
{# - Set up common variables -#}
7+
{%- set library_prefix = "%LIBRARY_PREFIX%" if build_platform == "windows" else "$PREFIX" -%}
8+
9+
mojo --version
10+
11+
12+
{#- Build any binaries -#}
13+
{% if bins %}
14+
{% for bin in bins %}
15+
mojo build {{ bin.extra_args | join(" ") }} {{ bin.path }} -o {{ library_prefix }}/bin/{{ bin.name }}
16+
{% endfor %}
17+
{% endif %}
18+
19+
{#- Build pkg -#}
20+
{% if pkg %}
21+
mojo package {{ pkg.extra_args | join(" ") }} {{ pkg.path }} -o {{ library_prefix }}/lib/mojo/{{ pkg.name}}.mojopkg
22+
{% endif %}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
use super::config::{MojoBinConfig, MojoPkgConfig};
2+
use minijinja::Environment;
3+
use serde::Serialize;
4+
5+
#[derive(Debug, Serialize)]
6+
pub struct BuildScriptContext {
7+
/// The directory where the source code is located, the manifest root.
8+
pub source_dir: String,
9+
/// Any executable artifacts to create.
10+
pub bins: Option<Vec<MojoBinConfig>>,
11+
/// Any packages to create.
12+
pub pkg: Option<MojoPkgConfig>,
13+
}
14+
15+
impl BuildScriptContext {
16+
pub fn render(&self) -> Vec<String> {
17+
let env = Environment::new();
18+
let template = env
19+
.template_from_str(include_str!("build_script.j2"))
20+
.unwrap();
21+
let rendered = template.render(self).unwrap().to_string();
22+
rendered.lines().map(|s| s.to_string()).collect()
23+
}
24+
}

0 commit comments

Comments
 (0)