Skip to content
Draft
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
3 changes: 3 additions & 0 deletions mozjs-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ name = "mozjs_sys"
doctest = false

[features]
default = ["mimalloc"] # Testingl only - remove me
mimalloc = [ "dep:mimalloc"]
debugmozjs = []
profilemozjs = []
jitspew = []
Expand All @@ -26,6 +28,7 @@ crown = []
oom_with_hook = []

[dependencies]
mimalloc = { version = "0.1.48", optional = true}
libc.workspace = true
encoding_c = "0.9.8"
encoding_c_mem = "0.2.6"
Expand Down
33 changes: 31 additions & 2 deletions mozjs-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ fn main() {

fn build_spidermonkey(build_dir: &Path) {
let target = env::var("TARGET").unwrap();
let cargo_manifest_dir = PathBuf::from(env::var_os("CARGO_MANIFEST_DIR").unwrap());
let make;

#[cfg(windows)]
Expand Down Expand Up @@ -210,24 +211,37 @@ fn build_spidermonkey(build_dir: &Path) {
}

cppflags.push(get_cc_rs_env_os("CPPFLAGS").unwrap_or_default());
cmd.env("CPPFLAGS", cppflags);

if let Some(makeflags) = env::var_os("CARGO_MAKEFLAGS") {
cmd.env("MAKEFLAGS", makeflags);
}

let mut cxxflags = vec![];

if env::var_os("CARGO_FEATURE_MIMALLOC").is_some() {
let mut flags = vec![];
// let include_dir = env::var("DEP_DFMALLOC_INCLUDE_DIR").expect("Required variable not set with feature dfmalloc");
// flags.push(format!("-I{}", &include_dir.replace("\\", "/")));
let header_dir = cargo_manifest_dir.join("src/custom_alloc").to_str().expect("utf-8").to_string();
flags.push(format!("-I{}", header_dir));
println!("cargo:rerun-if-changed={}", header_dir);

// flags.push("-DJS_USE_CUSTOM_ALLOCATOR".to_string());
cppflags.extend(flags.iter().map(|s| OsString::from(s)));
cxxflags.extend(flags);
}

if target.contains("apple") || target.contains("freebsd") || target.contains("ohos") {
cxxflags.push(String::from("-stdlib=libc++"));
}

cmd.env("CPPFLAGS", cppflags);

let base_cxxflags = env::var("CXXFLAGS").unwrap_or_default();
let mut cxxflags = cxxflags.join(" ");
cxxflags.push_str(&base_cxxflags);
cmd.env("CXXFLAGS", cxxflags);

let cargo_manifest_dir = PathBuf::from(env::var_os("CARGO_MANIFEST_DIR").unwrap());
let result = cmd
.args(&["-R", "-f"])
.arg(cargo_manifest_dir.join("makefile.cargo"))
Expand Down Expand Up @@ -292,6 +306,11 @@ fn build(build_dir: &Path, target: BuildTarget) {

build.flag(include_file_flag(build.get_compiler().is_like_msvc()));
build.flag(&js_config_path(build_dir));
let cargo_manifest_dir = PathBuf::from(env::var_os("CARGO_MANIFEST_DIR").unwrap());

let header_dir = cargo_manifest_dir.join("src/custom_alloc").to_str().expect("utf-8").to_string();
build.include(&header_dir);
println!("cargo:rerun-if-changed={}", header_dir);

for path in target.include_paths(build_dir) {
build.include(path);
Expand All @@ -313,6 +332,10 @@ fn build_bindings(build_dir: &Path, target: BuildTarget) {
config &= !CodegenConfig::DESTRUCTORS;
config &= !CodegenConfig::METHODS;

let cargo_manifest_dir = PathBuf::from(env::var_os("CARGO_MANIFEST_DIR").unwrap());

let header_dir = cargo_manifest_dir.join("src/custom_alloc").to_str().expect("utf-8").to_string();

let mut builder = bindgen::builder()
.rust_target(minimum_rust_target())
.header(target.path())
Expand All @@ -324,6 +347,7 @@ fn build_bindings(build_dir: &Path, target: BuildTarget) {
.size_t_is_usize(true)
.enable_cxx_namespaces()
.with_codegen_config(config)
.clang_arg(format!("-I{}", header_dir))
.clang_args(cc_flags(true));

if env::var("TARGET").unwrap().contains("wasi") {
Expand Down Expand Up @@ -432,6 +456,8 @@ fn link_static_lib_binaries(build_dir: &Path) {
// needing to use the WASI-SDK's clang for linking, which is annoying.
println!("cargo:rustc-link-lib=stdc++")
}
// FIXME: guard me, or remove me or whatever.
// println!("cargo:rustc-link-lib=mimalloc");

if target.contains("wasi") {
println!("cargo:rustc-link-lib=wasi-emulated-getpid");
Expand Down Expand Up @@ -463,6 +489,9 @@ fn should_build_from_source() -> bool {
} else if env::var_os("CARGO_FEATURE_INTL").is_none() {
println!("intl feature is disabled. Building from source directly.");
true
} else if env::var_os("CARGO_FEATURE_MIMALLOC").is_some() {
println!("mimalloc feature is enabled. Building from source directly.");
true
} else {
false
}
Expand Down
2 changes: 1 addition & 1 deletion mozjs-sys/mozjs/js/public/Utility.h

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

40 changes: 40 additions & 0 deletions mozjs-sys/mozjs/memory/build/embedder_fallback.cpp

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

3 changes: 2 additions & 1 deletion mozjs-sys/mozjs/memory/build/moz.build

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

4 changes: 4 additions & 0 deletions mozjs-sys/mozjs/memory/build/mozmemory_wrap.h

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

13 changes: 12 additions & 1 deletion mozjs-sys/mozjs/memory/mozalloc/mozalloc.cpp

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

6 changes: 3 additions & 3 deletions mozjs-sys/mozjs/mfbt/StringBuffer.h

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

Loading
Loading