Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix mozjs-sys always being out of date #524

Merged
merged 2 commits into from
Nov 22, 2024
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
2 changes: 1 addition & 1 deletion mozjs-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "mozjs_sys"
description = "System crate for the Mozilla SpiderMonkey JavaScript engine."
repository.workspace = true
version = "0.128.3-4"
version = "0.128.3-5"
authors = ["Mozilla"]
links = "mozjs"
build = "build.rs"
Expand Down
43 changes: 39 additions & 4 deletions mozjs-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use bindgen::callbacks::ParseCallbacks;
use bindgen::Formatter;
use flate2::read::GzDecoder;
use flate2::write::GzEncoder;
Expand Down Expand Up @@ -55,8 +56,7 @@ const SM_TARGET_ENV_VARS: &'static [&'static str] = &[
"OBJCOPY",
];

const EXTRA_FILES: &'static [&'static str] =
&["makefile.cargo", "src/rustfmt.toml", "src/jsapi.cpp"];
const EXTRA_FILES: &'static [&'static str] = &["makefile.cargo", "src/jsapi.cpp"];

/// Which version of moztools we expect
#[cfg(windows)]
Expand Down Expand Up @@ -647,6 +647,10 @@ fn ignore(path: &Path) -> bool {
return true;
}

if path.ends_with("js/src/configure") {
return true;
}

let ignored_extensions = ["pyc", "o", "so", "dll", "dylib"];

path.extension().map_or(false, |extension| {
Expand All @@ -656,7 +660,37 @@ fn ignore(path: &Path) -> bool {
})
}

/// Customization of [`bindgen::CargoCallbacks`]
///
/// This accounts for generated header files, to prevent needless rebuilds
#[derive(Debug)]
struct CustomCargoCallbacks;

impl CustomCargoCallbacks {
pub fn new() -> Self {
Self {}
}
}

impl ParseCallbacks for CustomCargoCallbacks {
fn header_file(&self, filename: &str) {
println!("cargo:rerun-if-changed={}", filename);
}
fn include_file(&self, filename: &str) {
// These header files are generated by the build-script
// so cargo checking for changes would only cause needless rebuilds.
if !filename.contains("dist/include") {
println!("cargo:rerun-if-changed={}", filename);
}
}

fn read_env_var(&self, key: &str) {
println!("cargo:rerun-if-env-changed={}", key);
}
}

mod jsglue {
use crate::CustomCargoCallbacks;
use std::env;
use std::path::{Path, PathBuf};

Expand Down Expand Up @@ -692,12 +726,13 @@ mod jsglue {
pub fn build(outdir: &Path) {
//let mut build = cxx_build::bridge("src/jsglue.rs"); // returns a cc::Build;
let mut build = cc::Build::new();
let include_path: PathBuf = outdir.join("dist/include");
let include_path = outdir.join("dist/include");

build
.cpp(true)
.file("src/jsglue.cpp")
.include(&include_path);

for flag in cc_flags(false) {
build.flag_if_supported(flag);
}
Expand Down Expand Up @@ -725,7 +760,7 @@ mod jsglue {
println!("cargo:rerun-if-changed=src/jsglue.cpp");
let mut builder = bindgen::Builder::default()
.header("./src/jsglue.cpp")
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
.parse_callbacks(Box::new(CustomCargoCallbacks::new()))
.size_t_is_usize(true)
.formatter(bindgen::Formatter::Rustfmt)
.clang_arg("-x")
Expand Down