Files
regorus/mimalloc/mimalloc-sys/build.rs
Anand Krishnamoorthi 6dc505c88b build: Add xtask automation for binding version management (#491)
* build: Add xtask automation for binding version management

Introduces a dedicated xtask crate that keeps language binding versions
in sync with the core regorus crate, following the workflow pattern used
by rust-analyzer, gitoxide, and ripgrep.

Key features:
- Git-based change detection: compares binding source files against a
  base ref (merge-base with origin/main by default) plus unstaged/
  untracked files to identify which bindings have been modified
- SemVer-aware bumping: binding edits trigger a minor version increment
  (e.g. 0.5.1 → 0.6.0) under pre-1.0 semantics, signaling potential
  breaking changes; clean bindings simply align to the root version
- Multi-language support: updates Cargo manifests (Rust FFI, Java,
  Python, WASM, Ruby), Maven pom.xml (Java), Ruby version constants,
  and C# project files in a single pass
- CI integration: --check mode fails fast when manifests are out of
  sync, ensuring pre-commit and release-plz workflows catch stale
  versions before merge

Integration points:
- release-plz.toml: runs cargo xtask bindings --base-ref origin/main
  after bumping the root crate, so binding versions are updated
  atomically during the release process
- scripts/pre-commit: invokes cargo xtask bindings --check to block
  commits that would leave bindings out of sync
- .cargo/config.toml: defines cargo xtask alias for convenience

Documentation includes inline examples showing how version bumps behave
when bindings are ahead/behind the root, and notes that the minor
field acts as the major version under SemVer 0.y.z initial development
phase.

Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>

* build: refresh xtask tooling, workflows, and locks

- cargo xtask bindings: keep the binding version-sync pipeline intact
- cargo xtask update-deps: new helper to regenerate workspace/binding Cargo.lock files
- workflows: auto-detect the Java jar version in CI and temporarily disable the Ruby workflow
- lock files: refresh root + binding snapshots after the dependency sweep

Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>

---------

Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
2025-10-28 16:10:54 -05:00

72 lines
2.2 KiB
Rust

// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
use std::boxed::Box;
use std::env;
use std::error::Error;
use std::fs;
use std::path::PathBuf;
fn main() -> Result<(), Box<dyn Error>> {
compile_mimalloc();
let build_dir = get_build_dir()?;
println!(
"cargo:rerun-if-changed={}",
build_dir.join("mimalloc").display()
);
if env::var("CARGO_CFG_TARGET_OS").as_deref() == Ok("windows") {
// Required for privilege-related APIs used by the Windows static build of mimalloc.
println!("cargo:rustc-link-lib=advapi32");
}
Ok(())
}
// Compile mimalloc source code and link it to the crate.
// The cc crate is used to compile the source code into a static library.
// We don't use the cmake crate to compile the source code because the mimalloc build system
// loads extra libraries, changes the name and path around, and does other things that are
// difficult to handle. The cc crate is much simpler and more predictable.
fn compile_mimalloc() {
let mimalloc_vendor_dir = PathBuf::from("mimalloc");
let mut build = cc::Build::new();
let include_dir = mimalloc_vendor_dir.join("include");
let src_dir = mimalloc_vendor_dir.join("src");
let static_file = src_dir.join("static.c");
assert!(include_dir.exists(), "include_dir: {include_dir:?}");
assert!(src_dir.exists(), "src_dir: {src_dir:?}");
assert!(static_file.exists(), "static_file: {static_file:?}");
build.include(include_dir);
build.include(src_dir);
build.file(static_file);
if build.get_compiler().is_like_msvc() {
build.static_crt(true);
}
// turn off debug mode
build.define("MI_DEBUG", "0");
// turning on optimizations doesn't seem to make a difference
//build.opt_level(3);
// log the command that will be run
build.cargo_debug(true);
// turn off warnings from the mimalloc code
build.cargo_warnings(false);
build.compile("mimalloc");
}
fn get_build_dir() -> Result<PathBuf, Box<dyn Error>> {
let manifest_dir = env::var("CARGO_MANIFEST_DIR")?;
let build_dir = PathBuf::from(manifest_dir.as_str());
let normalized_build_dir = fs::canonicalize(build_dir)?;
Ok(normalized_build_dir)
}