Skip to content
Open
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
5 changes: 3 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ jobs:
-i mxl_build_container_with_source \
bash -c "
cd /workspace/mxl/rust && \
cargo build --release --all-targets --locked
cargo build --release --features mxl-fabrics-ofi --all-targets --locked
"

- name: Test the Rust bindings
Expand All @@ -336,7 +336,7 @@ jobs:
-i mxl_build_container_with_source \
bash -c "
cd /workspace/mxl/rust && \
cargo test --release --all-targets --locked -- --test-threads=1 --show-output
cargo test --release --all-targets --features mxl-fabrics-ofi --locked -- --test-threads=1 --show-output
" 2>&1 | tee test.log
status=${PIPESTATUS[0]}
set -e
Expand All @@ -354,3 +354,4 @@ jobs:
} >> "$GITHUB_STEP_SUMMARY"
fi
exit "${status}"

2 changes: 1 addition & 1 deletion rust/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
.DS_Store
.idea
.vscode
target
/target
77 changes: 75 additions & 2 deletions rust/Cargo.lock

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

1 change: 1 addition & 0 deletions rust/mxl-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ cmake = "0.1.54"

[features]
mxl-not-built = []
mxl-fabrics-ofi = []
77 changes: 77 additions & 0 deletions rust/mxl-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,61 @@ fn get_bindgen_specs() -> BindgenSpecs {
}
}

fn get_bindgen_specs_fabrics() -> BindgenSpecs {
let header = "wrapper-fabrics.h".to_string();

let manifest_dir =
PathBuf::from(env::var("CARGO_MANIFEST_DIR").expect("failed to get current directory"));
let repo_root = manifest_dir.parent().unwrap().parent().unwrap();
let mut includes_dirs = vec![
repo_root
.join("lib")
.join("include")
.to_string_lossy()
.to_string(),
repo_root
.join("lib")
.join("fabrics")
.join("include")
.to_string_lossy()
.to_string(),
];
if cfg!(not(feature = "mxl-not-built")) {
let out_dir = PathBuf::from(std::env::var("OUT_DIR").unwrap());
let build_version_dir = out_dir.join("include").to_string_lossy().to_string();

includes_dirs.push(build_version_dir);

// Rebuild if any file in lib/ changes
let lib_root = repo_root.join("lib");
println!("cargo:rerun-if-changed={}", lib_root.display());

let dst = cmake::Config::new(repo_root)
.generator("Ninja")
.configure_arg("--preset")
.configure_arg(BUILD_VARIANT)
.configure_arg("-B")
.configure_arg(out_dir.join("build"))
.define("MXL_ENABLE_FABRICS_OFI", "ON")
.define("BUILD_DOCS", "OFF")
.define("BUILD_TESTS", "OFF")
.define("BUILD_TOOLS", "OFF")
.build();

println!(
"cargo:rustc-link-search={}",
dst.join("lib/fabrics/ofi").display()
);
println!("cargo:rustc-link-lib=mxl");
println!("cargo:rustc-link-lib=mxl-fabrics");
}

BindgenSpecs {
header,
includes_dirs,
}
}

fn main() {
let bindgen_specs = get_bindgen_specs();
for include_dir in &bindgen_specs.includes_dirs {
Expand Down Expand Up @@ -90,6 +145,28 @@ fn main() {
bindings
.write_to_file(out_path.join("bindings.rs"))
.expect("Could not write bindings");

if cfg!(feature = "mxl-fabrics-ofi") {
let fabrics_bindings = bindgen::builder()
.clang_args(
get_bindgen_specs_fabrics()
.includes_dirs
.iter()
.map(|dir| format!("-I{dir}")),
)
.header("wrapper-fabrics.h")
.derive_default(true)
.derive_debug(true)
.prepend_enum_name(false)
.dynamic_library_name("libmxlfabrics")
.dynamic_link_require_all(false)
.parse_callbacks(Box::new(CB))
.generate()
.unwrap();
fabrics_bindings
.write_to_file(out_path.join("fabrics_bindings.rs"))
.expect("Could not write fabrics bindings");
}
}

#[derive(Debug)]
Expand Down
5 changes: 5 additions & 0 deletions rust/mxl-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,8 @@
extern crate libloading;

include!(concat!(env!("OUT_DIR"), "/bindings.rs"));

#[cfg(feature = "mxl-fabrics-ofi")]
pub mod fabrics {
include!(concat!(env!("OUT_DIR"), "/fabrics_bindings.rs"));
}
4 changes: 4 additions & 0 deletions rust/mxl-sys/wrapper-fabrics.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// SPDX-FileCopyrightText: 2026 Contributors to the Media eXchange Layer project.
// SPDX-License-Identifier: Apache-2.0

#include "mxl/fabrics.h"
7 changes: 7 additions & 0 deletions rust/mxl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ serde.workspace = true
clap.workspace = true
serde_json.workspace = true
tracing-subscriber.workspace = true
ctrlc = "3"
base64 = "0.22"

[features]
mxl-not-built = ["mxl-sys/mxl-not-built"]
mxl-fabrics-ofi = ["mxl-sys/mxl-fabrics-ofi"]

[[example]]
name = "fabrics-demo"
required-features = ["mxl-fabrics-ofi"]
Loading
Loading