Skip to content

Commit

Permalink
Update typos and style changes
Browse files Browse the repository at this point in the history
  • Loading branch information
wusyong authored and sagudev committed Mar 28, 2024
1 parent c649e64 commit 1648e1c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ Mozjs is currently tracking SpiderMonkey on [ESR-115](https://searchfox.org/mozi

## Building from Pre-built Archive

SpiderMonkey is very large which could take a long time to compile. If building with default
feature, `mozjs` provides a pre-built archive which can be linked against. You can also create
SpiderMonkey is very large and can take a long time to compile. If building with default
features, `mozjs` provides a pre-built archive which can be linked against. You can also create
your own archive and link to it. `mozjs` currently offers two environment variables to enable
this feature:

- `MOZJS_CREATE_ARCHIVE=1` will create a SpiderMonkey binary tarball for release usage. It will
- `MOZJS_CREATE_ARCHIVE=1` will create a SpiderMonkey binary archive for release usage. It will
be created in the `target` directory.
- `MOZJS_ARCHIVE` can be used to build against a pre-built archive. Using this flag compiling
- `MOZJS_ARCHIVE` can be used to build against a pre-built archive. Using this flag, compiling
SpiderMonkey and the bindgen wrappers is unnecessary. There are two ways to use it:
- `MOZJS_ARCHIVE=path/to/libmozjs.tar.gz`: This option will look for the archive at the local
path, extract it, and then link against the static libraries included in the archive.
Expand Down
23 changes: 13 additions & 10 deletions mozjs-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,16 @@ fn main() {
// Used by mozjs downstream, don't remove.
println!("cargo:outdir={}", build_dir.display());

// Check if we can link with pre-built archive first, and decide if it needs to build from source.
if should_build_from_source(&build_dir) {
// Check if we can link with pre-built archive , and decide if it needs to build from source.
let mut build_from_source = should_build_from_source();
if !build_from_source {
if let Err(e) = link_static_lib_binaries(&build_dir) {
println!("cargo:warning=Failed to link pre-built archive by {e}. Building from source instead.");
build_from_source = true;
}
}

if build_from_source {
fs::create_dir_all(&build_dir).expect("could not create build dir");
build_spidermonkey(&build_dir);
build_jsapi(&build_dir);
Expand Down Expand Up @@ -92,7 +100,7 @@ fn main() {

/// Check env variable conditions to decide if we need to link pre-built archive first.
/// And then return bool value to notify if we need to build from source instead.
fn should_build_from_source(build_dir: &Path) -> bool {
fn should_build_from_source() -> bool {
if env::var_os("MOZJS_FROM_SOURCE").is_some() {
println!("Environment variable MOZJS_FROM_SOURCE is set. Building from source directly.");
true
Expand All @@ -108,13 +116,7 @@ fn should_build_from_source(build_dir: &Path) -> bool {
println!("streams feature isn't enabled. Building from source directly.");
true
} else {
match link_static_lib_binaries(&build_dir) {
Ok(()) => false,
Err(e) => {
println!("cargo:warning=Failed to link pre-built archive by {e}. Building from source instead.");
true
}
}
false
}
}

Expand Down Expand Up @@ -854,6 +856,7 @@ fn link_static_lib_binaries(build_dir: &Path) -> Result<(), std::io::Error> {
if let Ok(archive) = env::var("MOZJS_ARCHIVE") {
// If the archive variable is present, assume it's a URL base to download from.
let archive = download_archive(Some(&archive)).unwrap_or(PathBuf::from(archive));
// Panic directly since the archive is specified manually.
decompress_static_lib(&archive, build_dir).unwrap();
} else {
let archive = download_archive(None)?;
Expand Down

0 comments on commit 1648e1c

Please sign in to comment.