Skip to content

Commit b7b1f3d

Browse files
author
Alan Jeffrey
committed
Updated Rust bindings for SM 60
1 parent 6ba4904 commit b7b1f3d

15 files changed

+263
-104
lines changed

.travis.yml

+12-6
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,36 @@ rust:
55
- stable
66
sudo: 9000
77
dist: trusty
8-
98
os:
109
- linux
1110
- osx
11+
osx_image: xcode9.3
1212

1313
addons:
1414
apt:
1515
sources:
1616
- ubuntu-toolchain-r-test
1717
- llvm-toolchain-trusty-5.0
1818
packages:
19+
- autoconf2.13
1920
- g++-6
2021
- clang-5.0
2122

2223
env:
2324
- FEATURES=""
2425
- FEATURES="--features debugmozjs"
2526

26-
script:
27-
- cargo build --verbose --verbose $FEATURES
28-
- cargo test $FEATURES
27+
before_script:
28+
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then export CC=gcc-6; export CXX=g++-6; fi
29+
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update; brew install [email protected] ccache yasm; fi
2930

30-
before_install:
31-
if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update; brew install yasm; fi
31+
script:
32+
- ccache -z
33+
- CCACHE=$(which ccache) travis_wait cargo build --verbose $FEATURES
34+
- CCACHE=$(which ccache) RUST_BACKTRACE=1 cargo test --verbose $FEATURES
35+
- ccache -s
3236

3337
notifications:
3438
webhooks: http://build.servo.org:54856/travis
39+
40+
cache: ccache

Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ exclude = [
1717

1818
[features]
1919
debugmozjs = []
20-
promises = []
2120

2221
[lib]
2322
name = "mozjs_sys"

README.md

+23-5
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ set MOZTOOLS_PATH=C:\mozilla-build\msys\bin;C:\mozilla-build\mozmake;C:\mozilla-
4848
set LIBCLANG_PATH=C:\Program Files\LLVM\lib
4949
```
5050

51+
5. Set environment variables so the build script can find Python 2.7 and Autoconf 2.13:
52+
```
53+
set AUTOCONF=C:\mozilla-build\msys\local\bin\autoconf-2.13
54+
set NATIVE_WIN32_PYTHON=C:\mozilla-build\python\python2.7.exe
55+
```
56+
5157
You can now build and test the crate using cargo:
5258
```
5359
cargo build
@@ -61,10 +67,22 @@ Upgrading
6167

6268
In order to upgrade to a new version of SpiderMonkey:
6369

64-
1. Download the tarball corresponding to the desired mozilla-central commit
65-
from [treeherder's SM-tc(pkg) job][tc].
66-
2. Update `etc/COMMIT`.
67-
3. Run `python3 ./etc/update.py path/to/tarball`.
70+
1. Find the mozilla-release commit for the desired version of SpiderMonkey, at
71+
https://treeherder.mozilla.org/#/jobs?repo=mozilla-release&filter-searchStr=spidermonkey%20pkg.
72+
You are looking for an SM(pkg) tagged with FIREFOX_RELEASE.
73+
Take a note of the commit number to the left (a hex number such as ac4fbb7aaca0).
74+
75+
2. Click on the SM(pkg) link, which will open a panel with details of the
76+
commit, including an artefact uploaded link, with a name of the form
77+
mozjs-*version*.tar.bz2. Download it and save it locally.
78+
79+
3. Look at the patches in `etc/patches/*.patch`, and remove any that no longer apply
80+
(with a bit of luck this will be all of them).
81+
82+
4. Run `python3 ./etc/update.py path/to/tarball`.
83+
84+
5. Update `etc/COMMIT` with the commit number.
85+
86+
6. Build and test the bindings as above, then submit a PR!
6887

6988
[bindgen]: https://github.com/servo/rust-bindgen
70-
[tc]: https://treeherder.mozilla.org/#/jobs?repo=mozilla-central&filter-searchStr=Linux%20x64%20opt%20Spider%20Monkey,%20submitted%20by%20taskcluster%20%5BTC%5D%20Spidermonkey%20Package%20SM-tc(pkg)

appveyor.yml

+2-4
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ environment:
2626
C:\\Program Files\\Git\\cmd;\
2727
C:\\Program Files\\Git\\usr\\bin;\
2828
C:\\Program Files\\AppVeyor\\BuildAgent;"
29-
matrix:
30-
- CARGO_OPTS: ""
31-
- CARGO_OPTS: "--release"
3229

3330
# Uncomment to enable RDP & wait for exit. Connection info will be printed in the log.
3431
#init:
@@ -48,11 +45,12 @@ install:
4845
- call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat"
4946
- set MOZTOOLS_PATH=C:\mozilla-build\msys\bin;C:\mozilla-build\mozmake;C:\mozilla-build\yasm
5047
- set NATIVE_WIN32_PYTHON=C:/Python27/python.exe
48+
- set AUTOCONF=C:/mozilla-build/msys/local/bin/autoconf-2.13
5149
- rustc -vV
5250
- cargo -vV
5351

5452
build_script:
5553
- echo PATH %PATH%
5654
- echo VSINSTALLDIR %VSINSTALLDIR%
5755
- echo MOZTOOLS_PATH %MOZTOOLS_PATH%
58-
- cd %APPVEYOR_BUILD_FOLDER% && cargo build --verbose --verbose %CARGO_OPTS% && cargo test %CARGO_OPTS%
56+
- cd %APPVEYOR_BUILD_FOLDER% && cargo build --verbose --verbose && cargo test

build.rs

+35-4
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,14 @@ fn cc_flags() -> Vec<&'static str> {
5050
result.extend(&[
5151
"-std=c++14",
5252
"-DWIN32",
53+
// Don't use reinterpret_cast() in offsetof(),
54+
// since it's not a constant expression, so can't
55+
// be used in static_assert().
56+
"-D_CRT_USE_BUILTIN_OFFSETOF",
5357
]);
5458
} else {
5559
result.extend(&[
56-
"-std=gnu++11",
60+
"-std=gnu++14",
5761
"-fno-sized-deallocation",
5862
"-Wno-unused-parameter",
5963
"-Wno-invalid-offsetof",
@@ -95,11 +99,18 @@ fn build_jsapi() {
9599
.expect("Failed to run `make`");
96100

97101
assert!(result.success());
98-
println!("cargo:rustc-link-search=native={}/js/src", out_dir);
102+
println!("cargo:rustc-link-search=native={}/js/src/build", out_dir);
99103
println!("cargo:rustc-link-lib=static=js_static"); // Must come before c++
104+
println!("cargo:rustc-link-search=native={}/mozglue/build", out_dir);
105+
println!("cargo:rustc-link-lib=static=mozglue");
100106
if target.contains("windows") {
107+
println!("cargo:rustc-link-search=native={}/dist/bin", out_dir);
101108
println!("cargo:rustc-link-lib=winmm");
102109
println!("cargo:rustc-link-lib=psapi");
110+
println!("cargo:rustc-link-lib=user32");
111+
println!("cargo:rustc-link-lib=Dbghelp");
112+
println!("cargo:rustc-link-search=native={}/config/external/nspr/pr", out_dir);
113+
println!("cargo:rustc-link-lib=nspr4");
103114
if target.contains("gnu") {
104115
println!("cargo:rustc-link-lib=stdc++");
105116
}
@@ -114,7 +125,7 @@ fn build_jsapi() {
114125

115126
fn build_jsglue() {
116127
let out = PathBuf::from(env::var("OUT_DIR").unwrap());
117-
128+
118129
let mut build = cc::Build::new();
119130
build.cpp(true);
120131

@@ -132,6 +143,8 @@ fn build_jsglue() {
132143

133144
build.file("src/jsglue.cpp");
134145
build.include(out.join("dist/include"));
146+
build.include(out.join("js/src"));
147+
135148
build.compile("jsglue");
136149
}
137150

@@ -142,6 +155,7 @@ fn build_jsglue() {
142155
/// generated, see the `const` configuration variables below.
143156
fn build_jsapi_bindings() {
144157
let out = PathBuf::from(env::var("OUT_DIR").unwrap());
158+
let rustfmt_config = Some(PathBuf::from("rustfmt.toml"));
145159

146160
// By default, constructors, destructors and methods declared in .h files are inlined,
147161
// so their symbols aren't available. Adding the -fkeep-inlined-functions option
@@ -160,7 +174,10 @@ fn build_jsapi_bindings() {
160174
.rustified_enum(".*")
161175
.enable_cxx_namespaces()
162176
.with_codegen_config(config)
177+
.rustfmt_bindings(true)
178+
.rustfmt_configuration_file(rustfmt_config)
163179
.clang_arg("-I").clang_arg(out.join("dist/include").to_str().expect("UTF-8"))
180+
.clang_arg("-I").clang_arg(out.join("js/src").to_str().expect("UTF-8"))
164181
.clang_arg("-x").clang_arg("c++");
165182

166183
if cfg!(windows) {
@@ -175,14 +192,20 @@ fn build_jsapi_bindings() {
175192
}
176193
}
177194

195+
if let Ok(flags) = env::var("CLANGFLAGS") {
196+
for flag in flags.split_whitespace() {
197+
builder = builder.clang_arg(flag);
198+
}
199+
}
200+
178201
for flag in cc_flags() {
179202
builder = builder.clang_arg(flag);
180203
}
181204

182205
builder = builder.clang_arg("-include");
183206
builder = builder.clang_arg(out.join("js/src/js-confdefs.h").to_str().expect("UTF-8"));
184207

185-
println!("Generting bindings {:?}.", builder.command_line_flags());
208+
println!("Generting bindings {:?} {}.", builder.command_line_flags(), bindgen::clang_version().full);
186209

187210
for ty in UNSAFE_IMPL_SYNC_TYPES {
188211
builder = builder.raw_line(format!("unsafe impl Sync for root::{} {{}}", ty));
@@ -218,7 +241,9 @@ fn build_jsapi_bindings() {
218241
bindings.write_to_file(out.join("jsapi.rs"))
219242
.expect("Should write bindings to file OK");
220243

244+
println!("cargo:rerun-if-changed=rustfmt.toml");
221245
println!("cargo:rerun-if-changed=src/jsglue.hpp");
246+
println!("cargo:rerun-if-changed=src/jsglue.cpp");
222247
}
223248

224249
/// JSAPI types for which we should implement `Sync`.
@@ -270,6 +295,7 @@ const WHITELIST_FUNCTIONS: &'static [&'static str] = &[
270295
const OPAQUE_TYPES: &'static [&'static str] = &[
271296
"JS::Auto.*Impl",
272297
"JS::Auto.*Vector.*",
298+
"JS::PersistentRooted.*",
273299
"JS::ReadOnlyCompileOptions",
274300
"JS::Rooted<JS::Auto.*Vector.*>",
275301
"JS::detail::CallArgsBase.*",
@@ -279,6 +305,7 @@ const OPAQUE_TYPES: &'static [&'static str] = &[
279305
"mozilla::BufferList",
280306
"mozilla::Maybe.*",
281307
"mozilla::UniquePtr.*",
308+
"mozilla::Variant",
282309
];
283310

284311
/// Types for which we should NEVER generate bindings, even if it is used within
@@ -289,6 +316,9 @@ const BLACKLIST_TYPES: &'static [&'static str] = &[
289316
// We provide our own definition because we need to express trait bounds in
290317
// the definition of the struct to make our Drop implementation correct.
291318
"JS::Heap",
319+
// We provide our own definition because SM's use of templates
320+
// is more than bindgen can cope with.
321+
"JS::Rooted",
292322
// Bindgen generates bitfields with private fields, so they cannot
293323
// be used in const expressions.
294324
"JSJitInfo",
@@ -299,5 +329,6 @@ const MODULE_RAW_LINES: &'static [(&'static str, &'static str)] = &[
299329
("root", "pub type FILE = ::libc::FILE;"),
300330
("root", "pub type JSJitInfo = ::jsjit::JSJitInfo;"),
301331
("root::JS", "pub type Heap<T> = ::jsgc::Heap<T>;"),
332+
("root::JS", "pub type Rooted<T> = ::jsgc::Rooted<T>;"),
302333
("root::JS", "pub type AutoGCRooterTag = AutoGCRooter__bindgen_ty_1;"),
303334
];
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
diff --git a/mozjs/build/moz.configure/android-ndk.configure b/mozjs/build/moz.configure/android-ndk.configure
2+
index 1067b86..5193332 100644
3+
--- a/mozjs/build/moz.configure/android-ndk.configure
4+
+++ b/mozjs/build/moz.configure/android-ndk.configure
5+
@@ -301,6 +301,8 @@ def extra_toolchain_flags(android_system, android_sysroot, toolchain_dir,
6+
android_system,
7+
'-isystem',
8+
os.path.join(android_sysroot, 'usr', 'include'),
9+
+ '--sysroot',
10+
+ android_sysroot,
11+
'-gcc-toolchain',
12+
toolchain_dir,
13+
'-D__ANDROID_API__=%d' % android_version]

makefile.cargo

-4
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,6 @@ ifneq (,$(CARGO_FEATURE_DEBUGMOZJS))
6666
CONFIGURE_FLAGS += --enable-debug --disable-optimize --enable-gczeal
6767
endif
6868

69-
ifneq (,$(CARGO_FEATURE_PROMISES))
70-
CONFIGURE_FLAGS += --enable-sm-promise
71-
endif
72-
7369
ifneq (,$(CCACHE))
7470
CONFIGURE_FLAGS += --with-ccache=$(CCACHE)
7571
endif

mozjs/build/moz.configure/android-ndk.configure

+2
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,8 @@ def extra_toolchain_flags(android_system, android_sysroot, toolchain_dir,
301301
android_system,
302302
'-isystem',
303303
os.path.join(android_sysroot, 'usr', 'include'),
304+
'--sysroot',
305+
android_sysroot,
304306
'-gcc-toolchain',
305307
toolchain_dir,
306308
'-D__ANDROID_API__=%d' % android_version]

rustfmt.toml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Try to get all function signatures to fit on one line, so the jsapi file can be post-processed more easily
2+
max_width = 500

src/jsgc.rs

+21-2
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@ use jsapi::JSScript;
1212
use jsapi::JSString;
1313
use jsapi::JSTracer;
1414

15-
use libc::c_void;
16-
1715
use std::cell::UnsafeCell;
1816
use std::mem;
17+
use std::os::raw::c_void;
1918
use std::ptr;
2019

2120
/// A trait for JS types that can be registered as roots.
@@ -71,6 +70,15 @@ impl RootKind for JS::PropertyDescriptor {
7170
fn rootKind() -> JS::RootKind { JS::RootKind::Traceable }
7271
}
7372

73+
// Annoyingly, bindgen can't cope with SM's use of templates, so we have to roll our own.
74+
#[repr(C)]
75+
#[derive(Debug)]
76+
pub struct Rooted<T> {
77+
pub stack: *mut *mut Rooted<*mut c_void>,
78+
pub prev: *mut Rooted<*mut c_void>,
79+
pub ptr: T,
80+
}
81+
7482
/// A trait for types which can place appropriate GC barriers.
7583
/// * https://developer.mozilla.org/en-US/docs/Mozilla/Projects/SpiderMonkey/Internals/Garbage_collection#Incremental_marking
7684
/// * https://dxr.mozilla.org/mozilla-central/source/js/src/gc/Barrier.h
@@ -267,5 +275,16 @@ impl<T: IntoMutableHandle> From<T> for JS::MutableHandle<T::Target> {
267275
/// Methods for a CustomAutoRooter
268276
#[repr(C)]
269277
pub struct CustomAutoRooterVFTable {
278+
#[cfg(windows)]
279+
pub padding: [usize; 1],
280+
#[cfg(not(windows))]
281+
pub padding: [usize; 2],
270282
pub trace: unsafe extern "C" fn (this: *mut c_void, trc: *mut JSTracer),
271283
}
284+
285+
impl CustomAutoRooterVFTable {
286+
#[cfg(windows)]
287+
pub const PADDING: [usize; 1] = [0];
288+
#[cfg(not(windows))]
289+
pub const PADDING: [usize; 2] = [0, 0];
290+
}

0 commit comments

Comments
 (0)