Skip to content
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
19 changes: 18 additions & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,21 @@ jobs:
- name: Build
run: cargo build ${{ matrix.release.flag }} --verbose ${{ matrix.features.args }}
- name: Run tests
run: cargo test ${{ matrix.release.flag }} --all ${{ matrix.features.args }}
run: cargo test ${{ matrix.release.flag }} --all ${{ matrix.features.args }}

publish-scan:
runs-on: ubuntu-latest
name: publish-scan
defaults:
run:
shell: bash
steps:
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
- name: Checkout
uses: actions/checkout@v4
- name: update dependency
run: sudo apt-get update -y && sudo apt-get --reinstall install -y libc6-dev
- name: Dry-run workspace publish
run: cargo publish --workspace --exclude xtask --dry-run
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@

# cache dirs
.cache

# rust target
/target
8 changes: 8 additions & 0 deletions snmalloc-rs/snmalloc-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ categories = ["memory-management", "api-bindings"]
homepage = "https://github.com/microsoft/snmalloc"
repository = "https://github.com/microsoft/snmalloc"
build = "build.rs"
include = [
"Cargo.toml",
"build.rs",
"src/**",
"upstream/CMakeLists.txt",
"upstream/src/**",
"upstream/fuzzing/**",
]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[build-dependencies]
Expand Down
24 changes: 15 additions & 9 deletions snmalloc-rs/snmalloc-sys/build.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![allow(dead_code)]

use std::env;
use std::{env, path::{Path, PathBuf}};

#[derive(Debug, PartialEq)]
enum Compiler {
Expand All @@ -21,7 +21,8 @@ struct BuildConfig {
build_type: String,
msystem: Option<String>,
cmake_cxx_standard: String,
target_lib: String,
target_lib: String,
source_root: PathBuf,
features: BuildFeatures,
#[cfg(feature = "build_cc")]
builder: cc::Build,
Expand All @@ -44,6 +45,7 @@ impl std::fmt::Debug for BuildConfig {
.field("msystem", &self.msystem)
.field("cmake_cxx_standard", &self.cmake_cxx_standard)
.field("target_lib", &self.target_lib)
.field("source_root", &self.source_root)
.field("features", &self.features)
.finish()
}
Expand Down Expand Up @@ -74,12 +76,15 @@ impl BuildConfig {
let feature_debug = cfg!(feature = "debug");
let cargo_debug = env::var("DEBUG").map(|v| v == "true").unwrap_or(false);
let debug = feature_debug || cargo_debug;
let source_root =
PathBuf::from(env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set"))
.join("upstream");

#[cfg(feature = "build_cc")]
let builder = cc::Build::new();

#[cfg(not(feature = "build_cc"))]
let builder = Config::new("../..");
let builder = Config::new(&source_root);

let mut config = Self {
debug,
Expand All @@ -99,6 +104,7 @@ impl BuildConfig {
} else {
"snmallocshim-rust"
}).to_string(),
source_root,
features: BuildFeatures::new(),
builder,
compiler: Compiler::Unknown,
Expand Down Expand Up @@ -214,7 +220,7 @@ trait BuilderDefine {
fn flag_if_supported(&mut self, flag: &str) -> &mut Self;
fn build_lib(&mut self, target_lib: &str) -> std::path::PathBuf;
fn configure_output_dir(&mut self, out_dir: &str) -> &mut Self;
fn configure_cpp(&mut self, debug: bool) -> &mut Self;
fn configure_cpp(&mut self, debug: bool, source_root: &Path) -> &mut Self;
fn compiler_define(&mut self, key: &str, value: &str) -> &mut Self;
}

Expand All @@ -237,9 +243,9 @@ impl BuilderDefine for cc::Build {
self.out_dir(out_dir)
}

fn configure_cpp(&mut self, debug: bool) -> &mut Self {
self.include("../../src")
.file("../../src/snmalloc/override/rust.cc")
fn configure_cpp(&mut self, debug: bool, source_root: &Path) -> &mut Self {
self.include(source_root.join("src"))
.file(source_root.join("src/snmalloc/override/rust.cc"))
.cpp(true)
.debug(debug)
.static_crt(true)
Expand Down Expand Up @@ -268,7 +274,7 @@ impl BuilderDefine for cmake::Config {
self.out_dir(out_dir)
}

fn configure_cpp(&mut self, debug: bool) -> &mut Self {
fn configure_cpp(&mut self, debug: bool, _source_root: &Path) -> &mut Self {
self.define("SNMALLOC_RUST_SUPPORT", "ON")
.very_verbose(true)
.define("CMAKE_SH", "CMAKE_SH-NOTFOUND")
Expand Down Expand Up @@ -624,7 +630,7 @@ fn main() {
let mut config = BuildConfig::new();

config.builder
.configure_cpp(config.debug)
.configure_cpp(config.debug, &config.source_root)
.configure_output_dir(&config.out_dir);

// Apply all configurations
Expand Down
1 change: 1 addition & 0 deletions snmalloc-rs/snmalloc-sys/upstream/CMakeLists.txt
1 change: 1 addition & 0 deletions snmalloc-rs/snmalloc-sys/upstream/fuzzing
1 change: 1 addition & 0 deletions snmalloc-rs/snmalloc-sys/upstream/src
Loading