Files
consensus/pkg/rust/build.rs
T
zeekay 40c41f2efc pkg/rust: publish lux-consensus v1.22.0 to crates.io
Metadata polish for the public registry: correct `license = "MIT"`
(wrong) to `license-file = "LICENSE"` with the Lux Ecosystem License 1.2
vendored in-crate, sharpen the description (Quasar BFT, Wave/FPC/Photon/
Focus), add keywords/categories/homepage/readme/authors, and exclude
the historical `tests/*.old` snapshots from the published tarball.

build.rs: the Rust source has zero `extern "C"` symbols and never
actually consumed the sibling `libluxconsensus` C library, but the
unconditional `cargo:rustc-link-lib=luxconsensus` would break every
downstream consumer building from crates.io. Guard the link directives
on the static/dynamic library actually existing on disk so in-tree
development is unchanged and crates.io builds succeed cleanly. Skip
the link step entirely under `DOCS_RS`.

Published: https://crates.io/crates/lux-consensus/1.22.0
2026-05-13 00:18:34 -07:00

44 lines
1.5 KiB
Rust

use std::env;
use std::path::PathBuf;
fn main() {
// docs.rs builds: skip everything below.
if env::var("DOCS_RS").is_ok() {
return;
}
// This crate is pure Rust (no `extern "C"` symbols are referenced from
// src/lib.rs). The historical build.rs linked against a sibling C
// library (`libluxconsensus`) that is built alongside in the upstream
// repo, but no Rust code consumes those symbols.
//
// To keep in-tree development behaviour unchanged AND let downstream
// consumers (and crates.io) build without the C library on disk, we
// emit the link directives *only when the static or dynamic library
// actually exists on the filesystem*.
let dir = env::var("CARGO_MANIFEST_DIR").unwrap();
let c_lib_path = PathBuf::from(&dir).parent().unwrap().join("c/lib");
let candidates = [
c_lib_path.join("libluxconsensus.a"),
c_lib_path.join("libluxconsensus.dylib"),
c_lib_path.join("libluxconsensus.so"),
];
let any_exists = candidates.iter().any(|p| p.exists());
if any_exists {
println!("cargo:rustc-link-search=native={}", c_lib_path.display());
println!("cargo:rustc-link-lib=luxconsensus");
if cfg!(target_os = "macos") {
println!("cargo:rustc-link-arg=-Wl,-rpath,{}", c_lib_path.display());
}
}
// Rerun if the C library changes (or appears/disappears).
for c in &candidates {
println!("cargo:rerun-if-changed={}", c.display());
}
println!("cargo:rerun-if-env-changed=DOCS_RS");
}