Skip to content

Commit d7f2a34

Browse files
author
bors-servo
authored
Auto merge of #134 - asajeffrey:bindgenup, r=jdm
Run bindgen in build.rs This PR uses the bindgen crate to generate the Rust bindings for the `mozjs_sys` crate. In its current form, this means requiring llvm to be installed to build `mozjs_sys`. We could check those bindings in if we want to avoid that requirement, but this has its own problems. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/mozjs/134) <!-- Reviewable:end -->
2 parents 57b7967 + d40cfd5 commit d7f2a34

21 files changed

+2100
-77
lines changed

.travis.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,31 @@
11
language: rust
22
rust:
33
- nightly
4+
- beta
5+
- stable
46
sudo: 9000
57
dist: trusty
68

79
os:
810
- linux
911
- osx
1012

13+
addons:
14+
apt:
15+
sources:
16+
- ubuntu-toolchain-r-test
17+
- llvm-toolchain-trusty-5.0
18+
packages:
19+
- g++-6
20+
- clang-5.0
21+
1122
env:
1223
- FEATURES=""
1324
- FEATURES="--features debugmozjs"
1425

1526
script:
1627
- cargo build --verbose --verbose $FEATURES
28+
- cargo test $FEATURES
1729

1830
before_install:
1931
if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update; brew install yasm; fi

Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@ promises = []
2121

2222
[lib]
2323
name = "mozjs_sys"
24-
path = "lib.rs"
2524

2625
[dependencies]
2726
libc = "0.2"
2827
libz-sys = "1.0"
28+
29+
[build-dependencies]
30+
bindgen = "0.36.1"
31+
cc = "1.0"

README.md

Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,61 @@
1-
This repository contains the sources of [SpiderMonkey][sm] for use with
1+
This repository contains Rust bindings for [SpiderMonkey][sm] for use with
22
[Servo][s].
33

44
[sm]: https://developer.mozilla.org/en-US/docs/Mozilla/Projects/SpiderMonkey
55
[s]: https://servo.org/
66

7-
The bindings are in the [rust-mozjs repository][r-m].
7+
The bindings are to the raw SpiderMonkey API, higher-level bindings
8+
are in the [rust-mozjs repository][r-m].
89

910
[r-m]: https://github.com/servo/rust-mozjs/
1011

12+
Building
13+
========
14+
15+
Under Linux:
16+
17+
Install Clang (at least version 3.9), for example in a Debian-based Linux:
18+
```
19+
sudo apt-get install clang-6.0
20+
```
21+
22+
If you have more than one version of Clang installed, you can set the `LIBCLANG_PATH`
23+
environment variable, for example:
24+
```
25+
export LIBCLANG_PATH=/usr/lib/clang/4.0/lib
26+
```
27+
28+
Under Windows:
29+
30+
1. Follow the directions at
31+
https://developer.mozilla.org/en-US/docs/Mozilla/Developer_guide/Build_Instructions/Windows_Prerequisites
32+
33+
2. Open up a shell configured to use Visual Studio. This could be the
34+
one included with Visual Studio (e.g. Visual Studio 2017 / X64 Native
35+
Tools Command Prompt for VS 2017) or a shell in which you have run
36+
```
37+
"c:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Auxiliary\Build\vcvars64.bat"
38+
```
39+
40+
3. Set the `MOZTOOLS_PATH` environment variable to point to the tools from the Mozilla Build Package:
41+
```
42+
set MOZTOOLS_PATH=C:\mozilla-build\msys\bin;C:\mozilla-build\mozmake;C:\mozilla-build\yasm
43+
```
44+
45+
4. Download and install Clang for Windows (64 bit) from https://releases.llvm.org/download.html
46+
and set the `LIBCLANG_PATH` environment variable to its `lib` directory:
47+
```
48+
set LIBCLANG_PATH=C:\Program Files\LLVM\lib
49+
```
50+
51+
You can now build and test the crate using cargo:
52+
```
53+
cargo build
54+
cargo test
55+
cargo build --features debugmozjs
56+
cargo test --features debugmozjs
57+
```
58+
1159
Upgrading
1260
=========
1361

@@ -17,12 +65,6 @@ In order to upgrade to a new version of SpiderMonkey:
1765
from [treeherder's SM-tc(pkg) job][tc].
1866
2. Update `etc/COMMIT`.
1967
3. Run `python3 ./etc/update.py path/to/tarball`.
20-
4. Clone and build the [`servo/rust-bindgen`][bindgen] repository with llvm 3.9
21-
or newer.
22-
4. Clone the [`servo/rust-mozjs`][r-m] repository.
23-
5. For each supported platform (linux 32, linux 64, macos 64, windows gcc and msvc 64):
24-
* `$ cd path/to/rust-mozjs`
25-
* `$ ./etc/bindings-all.py <platform> ../path/to/bindgen ../path/to/clang/libs`
2668

2769
[bindgen]: https://github.com/servo/rust-bindgen
2870
[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

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
version: 1.0.{build}
2+
image: Visual Studio 2017
23

34
environment:
45
# The appveyor image we use has a pretty huge set of things installed... we make the
@@ -26,8 +27,8 @@ environment:
2627
C:\\Program Files\\Git\\usr\\bin;\
2728
C:\\Program Files\\AppVeyor\\BuildAgent;"
2829
matrix:
29-
- TARGET: nightly-x86_64-pc-windows-msvc
30-
- TARGET: nightly-x86_64-pc-windows-gnu
30+
- CARGO_OPTS: ""
31+
- CARGO_OPTS: "--release"
3132

3233
# Uncomment to enable RDP & wait for exit. Connection info will be printed in the log.
3334
#init:
@@ -37,35 +38,21 @@ environment:
3738

3839
# called after cloning, before building
3940
install:
41+
- set BUILD_ENV=msvc
42+
- set TARGET=nightly-x86_64-pc-windows-msvc
4043
- ps: Start-FileDownload "http://servo-rust.s3.amazonaws.com/build/MozillaBuildSetup-2.2.0.exe"
4144
- ps: .\MozillaBuildSetup-2.2.0.exe /S | Out-Null
4245
- ps: Start-FileDownload "https://static.rust-lang.org/dist/rust-${env:TARGET}.exe" -FileName "rust-install.exe"
4346
- ps: .\rust-install.exe /VERYSILENT /NORESTART /DIR="C:\rust" | Out-Null
4447
- ps: $env:PATH="$env:PATH;C:\rust\bin"
45-
# I can't make this work with a multi-line script (e.g. via |+ etc.), so we copy the if before every command
46-
- if %TARGET:*-msvc=msvc%==msvc set BUILD_ENV=msvc
47-
- if %TARGET:*-gnu=gnu%==gnu set BUILD_ENV=gnu
48-
- if %BUILD_ENV%==msvc call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\amd64\vcvars64.bat"
49-
- if %BUILD_ENV%==msvc copy C:\mozilla-build\yasm\yasm.exe C:\mozilla-build\msys\bin
50-
- if %BUILD_ENV%==msvc copy C:\mozilla-build\mozmake\mozmake.exe C:\mozilla-build\msys\bin
51-
- if %BUILD_ENV%==msvc set MOZTOOLS_PATH=C:\mozilla-build\msys\bin
52-
- if %BUILD_ENV%==msvc set NATIVE_WIN32_PYTHON=C:/Python27/python.exe
53-
- if %BUILD_ENV%==gnu set PATH=C:\msys64\mingw64\bin;C:\msys64\usr\bin\;%PATH%
54-
- if %BUILD_ENV%==gnu set MSYSTEM=MINGW64
55-
- if %BUILD_ENV%==gnu set MSYS=winsymlinks=lnk
56-
- if %BUILD_ENV%==gnu bash -lc "echo $MSYSTEM; pacman --needed --noconfirm -Sy pacman-mirrors"
57-
- if %BUILD_ENV%==gnu bash -lc "pacman --noconfirm -Sy"
58-
- if %BUILD_ENV%==gnu bash -lc "pacman -Sy --needed --noconfirm git mingw-w64-x86_64-toolchain tar make python2-setuptools"
59-
- if %BUILD_ENV%==gnu bash -lc "easy_install-2.7 pip virtualenv"
60-
- if %BUILD_ENV%==gnu bash -lc "mv /mingw64/bin/python2.exe /mingw64/bin/python2-mingw64.exe"
61-
- if %BUILD_ENV%==gnu bash -lc "mv /mingw64/bin/python2.7.exe /mingw64/bin/python2.7-mingw64.exe"
48+
- call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat"
49+
- set MOZTOOLS_PATH=C:\mozilla-build\msys\bin;C:\mozilla-build\mozmake;C:\mozilla-build\yasm
50+
- set NATIVE_WIN32_PYTHON=C:/Python27/python.exe
6251
- rustc -vV
6352
- cargo -vV
6453

6554
build_script:
6655
- echo PATH %PATH%
6756
- echo VSINSTALLDIR %VSINSTALLDIR%
6857
- echo MOZTOOLS_PATH %MOZTOOLS_PATH%
69-
- if %BUILD_ENV%==msvc cd %APPVEYOR_BUILD_FOLDER% && cargo build --verbose --verbose
70-
- if %BUILD_ENV%==gnu bash -lc "cd $APPVEYOR_BUILD_FOLDER; cargo build --verbose --verbose"
71-
58+
- cd %APPVEYOR_BUILD_FOLDER% && cargo build --verbose --verbose %CARGO_OPTS% && cargo test %CARGO_OPTS%

0 commit comments

Comments
 (0)