Skip to content

feat: mojo build backend #251

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
Jul 30, 2025
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
61 changes: 58 additions & 3 deletions Cargo.lock

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

34 changes: 34 additions & 0 deletions crates/pixi-build-mojo/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[package]
name = "pixi-build-mojo"
version = "0.1.0"
edition.workspace = true

[profile.dev.package]
insta.opt-level = 3
similar.opt-level = 3

[dependencies]
async-trait = { workspace = true }
chrono = { workspace = true }
indexmap = { workspace = true }
miette = { workspace = true }
minijinja = { workspace = true }
rattler_conda_types = { workspace = true }
rattler_package_streaming = { workspace = true }
rattler-build = { workspace = true }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
tempfile = { workspace = true }
tokio = { workspace = true, features = ["macros"] }

pixi-build-backend = { workspace = true }

pixi_build_types = { workspace = true }
pixi_manifest = { workspace = true }
pixi_build_type_conversions = { workspace = true }

recipe-stage0 = { workspace = true }

[dev-dependencies]
insta = { version = "1.42.1", features = ["yaml", "redactions", "filters"] }
rstest = "0.23"
22 changes: 22 additions & 0 deletions crates/pixi-build-mojo/src/build_script.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{%- set is_cmd_exe = build_platform == "windows" -%}
{%- macro env(key) -%}
{%- if is_cmd_exe %}{{ "%" ~ key ~ "%" }}{% else %}{{ "$" ~key }}{% endif -%}
{% endmacro -%}

{# - Set up common variables -#}
{%- set library_prefix = "%LIBRARY_PREFIX%" if build_platform == "windows" else "$PREFIX" -%}

mojo --version


{#- Build any binaries -#}
{% if bins %}
{% for bin in bins %}
mojo build {{ bin.extra_args | join(" ") }} {{ bin.path }} -o {{ library_prefix }}/bin/{{ bin.name }}
{% endfor %}
{% endif %}

{#- Build pkg -#}
{% if pkg %}
mojo package {{ pkg.extra_args | join(" ") }} {{ pkg.path }} -o {{ library_prefix }}/lib/mojo/{{ pkg.name}}.mojopkg
{% endif %}
24 changes: 24 additions & 0 deletions crates/pixi-build-mojo/src/build_script.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use super::config::{MojoBinConfig, MojoPkgConfig};
use minijinja::Environment;
use serde::Serialize;

#[derive(Debug, Serialize)]
pub struct BuildScriptContext {
/// The directory where the source code is located, the manifest root.
pub source_dir: String,
/// Any executable artifacts to create.
pub bins: Option<Vec<MojoBinConfig>>,
/// Any packages to create.
pub pkg: Option<MojoPkgConfig>,
}

impl BuildScriptContext {
pub fn render(&self) -> Vec<String> {
let env = Environment::new();
let template = env
.template_from_str(include_str!("build_script.j2"))
.unwrap();
let rendered = template.render(self).unwrap().to_string();
rendered.lines().map(|s| s.to_string()).collect()
}
}
Loading
Loading