Skip to content

Commit e3950d5

Browse files
committed
feat: add rust backend
1 parent aa1ca9d commit e3950d5

27 files changed

+1101
-5
lines changed

Cargo.lock

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

crates/pixi-build-cmake/src/stub.rs renamed to crates/pixi-build-backend/src/compilers.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
//! This module contains some functions that I copied from rattler-build. We
2-
//! should refactor these.
1+
//! We could expose the `default_compiler` function from the `rattler-build` crate
32
43
use rattler_conda_types::Platform;
54

6-
pub(crate) fn default_compiler(platform: Platform, language: &str) -> Option<String> {
5+
pub fn default_compiler(platform: Platform, language: &str) -> Option<String> {
76
Some(
87
match language {
98
// Platform agnostic compilers

crates/pixi-build-backend/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ pub mod protocol;
33
pub mod server;
44

55
pub mod common;
6+
pub mod compilers;
67
mod consts;
78
pub mod dependencies;
89
pub mod project;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use std::{
77
use miette::IntoDiagnostic;
88
use pixi_build_backend::{
99
common::{requirements, BuildConfigurationParams},
10+
compilers::default_compiler,
1011
traits::{project::new_spec, Dependencies},
1112
};
1213
use pixi_build_backend::{ProjectModel, Targets};
@@ -29,7 +30,6 @@ use rattler_package_streaming::write::CompressionLevel;
2930
use crate::{
3031
build_script::{BuildPlatform, BuildScriptContext},
3132
config::CMakeBackendConfig,
32-
stub::default_compiler,
3333
};
3434

3535
pub struct CMakeBuildBackend<P: ProjectModel> {

crates/pixi-build-cmake/src/main.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ mod build_script;
22
mod cmake;
33
mod config;
44
mod protocol;
5-
mod stub;
65

76
use protocol::CMakeBuildBackendInstantiator;
87

crates/pixi-build-rust/Cargo.toml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
[package]
2+
name = "pixi-build-rust"
3+
version = "0.1.3"
4+
edition.workspace = true
5+
6+
[dependencies]
7+
async-trait = { workspace = true }
8+
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 }
15+
miette = { workspace = true }
16+
minijinja = { workspace = true }
17+
parking_lot = { workspace = true }
18+
rattler_conda_types = { workspace = true }
19+
rattler_package_streaming = { workspace = true }
20+
rattler_virtual_packages = { workspace = true }
21+
rattler-build = { workspace = true }
22+
reqwest = { workspace = true }
23+
reqwest-middleware = { workspace = true }
24+
serde = { workspace = true, features = ["derive"] }
25+
serde_yaml = { workspace = true }
26+
serde_json = { workspace = true }
27+
toml_edit = { workspace = true }
28+
tempfile = { workspace = true }
29+
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 }
35+
36+
pixi-build-backend = { workspace = true }
37+
38+
pixi_build_types = { workspace = true }
39+
pixi_consts = { workspace = true }
40+
pixi_manifest = { workspace = true }
41+
pixi_spec = { workspace = true }
42+
pixi_build_type_conversions = { workspace = true }
43+
44+
jsonrpc-stdio-server = { workspace = true }
45+
jsonrpc-http-server = { workspace = true }
46+
jsonrpc-core = { workspace = true }
47+
48+
[dev-dependencies]
49+
insta = { version = "1.42.1", features = ["yaml", "redactions", "filters"] }
50+
toml_edit = { version = "0.22.24" }

crates/pixi-build-rust/pixi.lock

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

crates/pixi-build-rust/pixi.toml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
[workspace]
2+
authors = ["Bas Zalmstra <bas@prefix.dev>"]
3+
channels = ["conda-forge"]
4+
description = "Showcases how to create a simple C++ executable with Pixi"
5+
name = "pixi_build_rust"
6+
platforms = ["win-64", "linux-64", "osx-64", "osx-arm64"]
7+
preview = ["pixi-build"]
8+
version = "0.1.0"
9+
10+
# [tasks.start]
11+
# # Start the built executable
12+
# cmd = ".build/bin/sdl_example"
13+
# depends-on = ["build"]
14+
15+
[package]
16+
authors = ["Wolf Vollprecht <wolf@prefix.dev>"]
17+
description = "Showcases how to create a simple C++ executable with Pixi"
18+
name = "pixi-build-rust"
19+
version = "0.1.0"
20+
21+
22+
[dependencies]
23+
pixi-build-rust = { path = "." }
24+
25+
[package.build]
26+
backend = { name = "pixi-build-rust", version = "*" }
27+
28+
# [feature.build.dependencies]
29+
# cmake = "3.26.4.*"
30+
# cxx-compiler = "1.5.2.*"
31+
# make = ">=4.3,<5"
32+
# ninja = "1.11.1.*"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export OPENSSL_DIR="$PREFIX"
2+
cargo install --locked --root $PREFIX --path {{ source_dir }} --no-track
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
use minijinja::Environment;
3+
use serde::Serialize;
4+
5+
#[derive(Serialize)]
6+
pub struct BuildScriptContext {
7+
pub build_platform: BuildPlatform,
8+
pub source_dir: String,
9+
pub extra_args: Vec<String>,
10+
}
11+
12+
#[derive(Serialize)]
13+
#[serde(rename_all = "kebab-case")]
14+
pub enum BuildPlatform {
15+
Windows,
16+
Unix,
17+
}
18+
19+
impl BuildScriptContext {
20+
pub fn render(&self) -> Vec<String> {
21+
let env = Environment::new();
22+
let template = env
23+
.template_from_str(include_str!("build_script.j2"))
24+
.unwrap();
25+
let rendered = template.render(self).unwrap().to_string();
26+
rendered.lines().map(|s| s.to_string()).collect()
27+
}
28+
}

0 commit comments

Comments
 (0)