Skip to content
New issue

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

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

Already on GitHub? # to your account

Upgrades QuickJS to 2021-03-27, and support msvc and i686 targets #114

Open
wants to merge 50 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
d51a607
Switch to https://github.com/c-smile/quickjspp using git submodule
branchseer May 7, 2021
4eec0c7
Switch to https://github.com/lygstate/quickjs
branchseer May 7, 2021
28c00df
Switch to https://github.com/lygstate/quickjs
branchseer May 7, 2021
aef1f9e
Switch to quickiot branch
branchseer May 7, 2021
017528c
Revert debugger change
branchseer May 7, 2021
29c7127
Test passed for msvc x64
branchseer May 7, 2021
61f399e
Treat JSValue as an opaque type
branchseer May 9, 2021
fa0a3f4
rustfmt
branchseer May 9, 2021
796c921
use q::JS_NULL in js_null_value
branchseer May 9, 2021
167f3ae
Remove usages of JSValueUnion
branchseer May 9, 2021
9580795
JS_VALUE_GET_TAG -> JS_VALUE_GET_NORM_TAG
branchseer May 10, 2021
e26471c
Checkout submodules in gh actions
branchseer May 10, 2021
2afce11
Remove patches
branchseer May 10, 2021
559597b
typo fix
branchseer May 10, 2021
73531dc
Update quickjs submodules to my own fork
branchseer May 10, 2021
f14110d
Add missing neg ops
branchseer May 10, 2021
a846116
Remove the patch feature (since we've already applied the patch in th…
branchseer May 10, 2021
bdfa43e
Update gh actions to test all kinds of targets
branchseer May 10, 2021
f62e874
Remove empty os & target list
branchseer May 10, 2021
8fd60f3
Add target to the path that is used to find executables for valgrind
branchseer May 10, 2021
cecbe38
Set default value for QJS_TARGET
branchseer May 10, 2021
f871c07
Use CARGO_BUILD_TARGET in justfile
branchseer May 10, 2021
792c479
Install libclang on Windows
branchseer May 10, 2021
79049bf
Remove spaces in bash assignment
branchseer May 10, 2021
046bf68
Update pacman command
branchseer May 10, 2021
9e87834
Escape backslash on windows
branchseer May 10, 2021
6c31b08
Use powershell in setup windows
branchseer May 10, 2021
c7a9710
Try install llvm
branchseer May 10, 2021
baa17f1
Remove msys2 in PATH
branchseer May 10, 2021
3ece8c5
Install x64 clang and x86 gcc
branchseer May 10, 2021
eea37bc
Add mingw64 path into PATH
branchseer May 10, 2021
f293f37
Update libclang & gcc setup
branchseer May 10, 2021
2d3d3fb
Setup msvc targeting x86
branchseer May 10, 2021
8df2013
Indent fix
branchseer May 10, 2021
6dec8c8
Setup mingw32 for both i686 windows targets
branchseer May 10, 2021
e35b0f6
Try not adding mingw64 into PATH
branchseer May 10, 2021
197e6fd
Revert last 2 commits
branchseer May 10, 2021
e28a0b9
Install llvm
branchseer May 10, 2021
3992fda
choco install -y
branchseer May 10, 2021
a3207f6
Remove choco install
branchseer May 10, 2021
d417748
pacman --noconfirm -R mingw-w64-x86_64-clang
branchseer May 10, 2021
868e415
Remove mingw-w64-x86_64-clang-tools-extra
branchseer May 10, 2021
17499d2
Setup mingw64 gcc for x86_64 gnu target
branchseer May 10, 2021
5e160d9
Refine job name
branchseer May 10, 2021
d7b2131
Remove unused guide and justfile tasks
branchseer May 10, 2021
df979c3
Refine cc build file list
branchseer May 10, 2021
1e9920d
Build and test in release profile
patr0nus May 11, 2021
1756d0f
Add back opt_level
branchseer May 11, 2021
7d03949
Revert "Add back opt_level"
branchseer May 11, 2021
34c58c5
Revert "Build and test in release profile"
branchseer May 11, 2021
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
65 changes: 44 additions & 21 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,40 @@ on:

jobs:
test:
name: Test on ${{ matrix.os }} with features ${{ matrix.features }}
name: Test ${{ matrix.target }}
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- macOS-latest
- windows-latest
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
- os: ubuntu-latest
target: i686-unknown-linux-gnu
- os: macOS-latest
target: x86_64-apple-darwin
- os: windows-latest
target: x86_64-pc-windows-msvc
- os: windows-latest
target: i686-pc-windows-msvc
- os: windows-latest
target: x86_64-pc-windows-gnu
- os: windows-latest
target: i686-pc-windows-gnu
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v1
with:
submodules: true

- name: Install stable toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
target: ${{ matrix.target }}
components: rustfmt, clippy
if: matrix.os != 'windows-latest'

- name: Install stable toolchain (windows)
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
target: x86_64-pc-windows-gnu
override: true
if: matrix.os == 'windows-latest'

- name: Install `just` command runner
uses: extractions/setup-just@v1
Expand All @@ -54,13 +58,32 @@ jobs:
sudo apt-get install -y curl xz-utils build-essential gcc-multilib valgrind
if: matrix.os == 'ubuntu-latest'

- name: Setup (windows)
- name: Install LLVM
run: |
$env:PATH = "C:\msys64\mingw64\bin;C:\msys64\usr\bin;$env:PATH"
echo "PATH=${env:PATH}" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
echo "CARGO_BUILD_TARGET=x86_64-pc-windows-gnu" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
C:\\msys64\\usr\\bin\\bash.exe -lc "pacman --noconfirm -R mingw-w64-x86_64-clang-tools-extra mingw-w64-x86_64-clang"
choco install -y llvm
if: matrix.os == 'windows-latest'

- name: Setup mingw32 gcc for i686 gnu target
run: |
C:\\msys64\\usr\\bin\\bash.exe -lc "pacman --noconfirm -S mingw32/mingw-w64-i686-gcc"
echo "PATH=C:\msys64\mingw32\bin;${env:PATH}" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
if: matrix.target == 'i686-pc-windows-gnu'

- name: Setup mingw64 gcc for x86_64 gnu target
run: |
C:\\msys64\\usr\\bin\\bash.exe -lc "pacman --noconfirm -S mingw64/mingw-w64-x86_64-gcc"
echo "PATH=C:\msys64\mingw64\bin;${env:PATH}" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
if: matrix.target == 'x86_64-pc-windows-gnu'

- name: Set CARGO_BUILD_TARGET
env:
QJS_TARGET: ${{ matrix.target }}
run: |
echo "CARGO_BUILD_TARGET=$QJS_TARGET" >> $GITHUB_ENV
shell: bash


- name: Build (default features)
env:
FEATURES: ""
Expand Down Expand Up @@ -102,8 +125,8 @@ jobs:

- name: Lint
run: just lint
if: matrix.os == 'ubuntu-latest'
if: matrix.target == 'x86_64-unknown-linux-gnu'

- name: Check for leaks (Valgrind)
run: just valgrind
if: matrix.os == 'ubuntu-latest'
if: matrix.target == 'x86_64-unknown-linux-gnu'
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "libquickjs-sys/src/quickjs"]
path = libquickjs-sys/src/quickjs
url = https://github.com/patr0nus/quickjs
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ keywords = ["quickjs", "javascript", "js", "engine", "interpreter"]
features = [ "chrono", "bigint", "log" ]

[features]
patched = ["libquickjs-sys/patched"]
bigint = ["num-bigint", "num-traits", "libquickjs-sys/patched"]
bigint = ["num-bigint", "num-traits"]

[dependencies]
libquickjs-sys = { version = ">= 0.9.0, < 0.10.0", path = "./libquickjs-sys" }
Expand Down
23 changes: 1 addition & 22 deletions justfile
Original file line number Diff line number Diff line change
@@ -1,26 +1,5 @@
embed_dir := "./libquickjs-sys/embed/quickjs"

DOWNLOAD_URL := "https://bellard.org/quickjs/quickjs-2020-11-08.tar.xz"
FEATURES := "--all-features"

download-new:
test -d {{embed_dir}} && rm -r {{embed_dir}} || echo ""
mkdir {{embed_dir}} && \
curl -L {{DOWNLOAD_URL}} | tar xJv -C {{embed_dir}} --strip-components 1

download-cleanup:
rm -r "{{embed_dir}}/doc" "{{embed_dir}}/examples" "{{embed_dir}}/tests"
find "{{embed_dir}}" -type f | grep -E "\.(pdf|html|js|texi|sh)$" | xargs rm
find "{{embed_dir}}" -type f | grep test | xargs rm

generate-bindings:
(cd libquickjs-sys; bindgen wrapper.h -o embed/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

update-quickjs: download-new generate-bindings download-cleanup


debian-setup:
echo "Installing dependencies..."
sudo apt update && sudo apt-get install -y curl xz-utils build-essential gcc-multilib libclang-dev clang valgrind
Expand Down Expand Up @@ -53,4 +32,4 @@ lint:

valgrind:
echo "Checking for memory leaks..."
find target/debug/deps -maxdepth 1 -type f -executable | xargs valgrind --leak-check=full --error-exitcode=1
find target/{{env_var_or_default("CARGO_BUILD_TARGET", "")}}/debug/deps -maxdepth 1 -type f -executable | xargs valgrind --leak-check=full --error-exitcode=1
5 changes: 2 additions & 3 deletions libquickjs-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@ build = "build.rs"

[features]
bundled = ["cc", "copy_dir"]
patched = ["bundled"]
default = ["bundled"]

system = ["bindgen"]
system = []

[build-dependencies]
bindgen = { version = "0.57.0", optional = true }
bindgen = { version = "0.57.0" }
cc = { version = "1.0.66", optional = true }
copy_dir = { version = "0.1.2", optional = true }
15 changes: 1 addition & 14 deletions libquickjs-sys/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ wrapper.


*Version 0.9.0*
**Embedded VERSION: 2020-11-08**
**Embedded VERSION: 2021-03-27**

## Embedded vs system

Expand All @@ -19,16 +19,3 @@ If you want to use a version installed on your system, use:
```toml
libquickjs-sys = { version = "...", default-features = false, features = ["system"] }
```


## Updating the embedded bindings

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:

* (Install [just](https://github.com/casey/just))
* Update the download URL in ./justfile
* run `just update-quickjs`
83 changes: 18 additions & 65 deletions libquickjs-sys/build.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,21 @@
use std::path::{Path, PathBuf};
use std::path::PathBuf;

use std::env;

fn exists(path: impl AsRef<Path>) -> bool {
PathBuf::from(path.as_ref()).exists()
}

const LIB_NAME: &str = "quickjs";

#[cfg(all(not(feature = "system"), not(feature = "bundled")))]
fn main() {
panic!("Invalid config for crate libquickjs-sys: must enable either the 'bundled' or the 'system' feature");
}

#[cfg(feature = "system")]
extern crate bindgen;

#[cfg(feature = "system")]
fn main() {
#[cfg(not(feature = "bindgen"))]
panic!("Invalid configuration for libquickjs-sys: Must either enable the bundled or the bindgen feature");

#[cfg(feature = "patched")]
panic!("Invalid configuration for libquickjs-sys: the patched feature is incompatible with the system feature");

let lib: std::borrow::Cow<str> = if let Ok(lib) = env::var("QUICKJS_LIBRARY_PATH") {
lib.into()
} else if cfg!(unix) {
Expand All @@ -45,28 +37,21 @@ fn main() {

#[cfg(feature = "bundled")]
fn main() {
let embed_path = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()).join("embed");
let src_path = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()).join("src");
let quickjs_src_path = src_path.join("quickjs");
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());

let code_dir = out_path.join("quickjs");
if exists(&code_dir) {
std::fs::remove_dir_all(&code_dir).unwrap();
}
copy_dir::copy_dir(embed_path.join("quickjs"), &code_dir)
.expect("Could not copy quickjs directory");

#[cfg(feature = "patched")]
apply_patches(&code_dir);

std::fs::copy(
embed_path.join("static-functions.c"),
code_dir.join("static-functions.c"),
)
.expect("Could not copy static-functions.c");

eprintln!("Compiling quickjs...");
let quickjs_version =
std::fs::read_to_string(code_dir.join("VERSION")).expect("failed to read quickjs version");
let binding = bindgen::builder()
.header(src_path.join("wrapper.h").to_str().unwrap().to_string())
.whitelist_function("(__)?(JS|js)_.*")
.whitelist_var("JS_.*")
.whitelist_type("JS.*")
.generate()
.unwrap();
binding.write_to_file(out_path.join("bindings.rs")).unwrap();

let quickjs_version = std::fs::read_to_string(quickjs_src_path.join("VERSION"))
.expect("failed to read quickjs version");
cc::Build::new()
.files(
[
Expand All @@ -75,18 +60,19 @@ fn main() {
"libregexp.c",
"libunicode.c",
"quickjs.c",
// Custom wrappers.
"static-functions.c",
"quickjs-port.c",
]
.iter()
.map(|f| code_dir.join(f)),
.map(|f| quickjs_src_path.join(f)),
)
.file(src_path.join("static-functions.c"))
.define("_GNU_SOURCE", None)
.define(
"CONFIG_VERSION",
format!("\"{}\"", quickjs_version.trim()).as_str(),
)
.define("CONFIG_BIGNUM", None)
.flag_if_supported("/std:c11")
// The below flags are used by the official Makefile.
.flag_if_supported("-Wchar-subscripts")
.flag_if_supported("-Wno-array-bounds")
Expand All @@ -104,38 +90,5 @@ fn main() {
.flag_if_supported("-Wno-cast-function-type")
.flag_if_supported("-Wno-implicit-fallthrough")
.flag_if_supported("-Wno-enum-conversion")
// cc uses the OPT_LEVEL env var by default, but we hardcode it to -O2
// since release builds use -O3 which might be problematic for quickjs,
// and debug builds only happen once anyway so the optimization slowdown
// is fine.
.opt_level(2)
.compile(LIB_NAME);

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

#[cfg(feature = "patched")]
fn apply_patches(code_dir: &PathBuf) {
use std::fs;

eprintln!("Applying patches...");
let embed_path = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()).join("embed");
let patches_path = embed_path.join("patches");
for patch in fs::read_dir(patches_path).expect("Could not open patches directory") {
let patch = patch.expect("Could not open patch");
eprintln!("Applying {:?}...", patch.file_name());
let status = std::process::Command::new("patch")
.current_dir(&code_dir)
.arg("-i")
.arg(patch.path())
.spawn()
.expect("Could not apply patches")
.wait()
.expect("Could not apply patches");
assert!(
status.success(),
"Patch command returned non-zero exit code"
);
}
}
Loading