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

Timers and modules #55

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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 justfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ download-cleanup:
find "{{embed_dir}}" -type f | grep test | xargs rm

generate-bindings:
(cd libquickjs-sys; bindgen wrapper.h -o embed/bindings.rs -- -I ./embed)
(cd libquickjs-sys; bindgen wrapper.h -o src/bindings.rs -- -I ./embed)
# Update VERSION in README
sed -i "s/**Embedded VERSION: .*/**Embedded VERSION: $(cat ./libquickjs-sys/embed/quickjs/VERSION)**/" ./libquickjs-sys/README.md

Expand Down
6 changes: 4 additions & 2 deletions libquickjs-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ build = "build.rs"
bundled = ["copy_dir"]
patched = []
bignum = []
default = ["bundled"]
pic = []
debug = []
default = ["bundled","pic","debug"]

system = ["bindgen"]

[build-dependencies]
bindgen = { version = "0.51.0", optional = true }
copy_dir = { version = "0.1.2", optional = true }

regex = "1.3.1"
2 changes: 1 addition & 1 deletion libquickjs-sys/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ QuickJS sources and a pre-generated `bindings.rs` are included in the repo.

They are used if the `embedded` feature is enabled.

To updat the bindings, follow these steps:
To update the bindings, follow these steps:

* (Install [just](https://github.com/casey/just))
* Update the download URL in ./justfile
Expand Down
35 changes: 31 additions & 4 deletions libquickjs-sys/build.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use std::path::{Path, PathBuf};

use std::env;
use std::{env, fs};

use regex::Regex;

fn exists(path: impl AsRef<Path>) -> bool {
PathBuf::from(path.as_ref()).exists()
Expand Down Expand Up @@ -70,6 +72,7 @@ fn main() {
apply_patches(&code_dir);

eprintln!("Compiling quickjs...");
patch_makefile(code_dir.join("Makefile").as_path());
std::process::Command::new("make")
.arg(format!("lib{}.a", LIB_NAME))
.current_dir(&code_dir)
Expand All @@ -78,9 +81,6 @@ fn main() {
.wait()
.expect("Could not compile quickjs");

std::fs::copy("./embed/bindings.rs", out_path.join("bindings.rs"))
.expect("Could not copy bindings.rs");

// Instruct cargo to statically link quickjs.
println!(
"cargo:rustc-link-search=native={}",
Expand All @@ -89,6 +89,33 @@ fn main() {
println!("cargo:rustc-link-lib=static={}", LIB_NAME);
}

fn patch_makefile(makefile: &Path) {
let content = fs::read_to_string(makefile).unwrap();

let content = if cfg!(feature = "debug") {
Regex::new("CFLAGS_OPT=(.*) -O2")
.unwrap()
.replace_all(&content, "CFLAGS_OPT=$1 -O0 -g")
} else {
content.into()
};

let content = Regex::new("CROSS_PREFIX=")
.unwrap()
.replace_all(&content, "CROSS_PREFIX?=");

let content = if cfg!(feature = "pic") {
content
.replace("CFLAGS+=$(DEFINES)\n", "CFLAGS+=$(DEFINES) -fPIC\n")
.into()
} else {
content
};

fs::rename(makefile, makefile.with_extension("bak")).unwrap();
fs::write(makefile, content.as_bytes()).unwrap();
}

#[cfg(feature = "patched")]
fn apply_patches(code_dir: &PathBuf) {
use std::fs;
Expand Down
1 change: 1 addition & 0 deletions libquickjs-sys/embed/quickjs/quickjs.c
Original file line number Diff line number Diff line change
Expand Up @@ -14888,6 +14888,7 @@ static JSValue JS_CallInternal(JSContext *ctx, JSValueConst func_obj,

alloca_size = sizeof(JSValue) * (arg_allocated_size + b->var_count +
b->stack_size);

if (js_check_stack_overflow(ctx, alloca_size))
return JS_ThrowStackOverflow(ctx);

Expand Down
Loading