Bug 1277338 - Part 1: Turn js/src into the mozjs-sys crate; r=sfink
authorNick Fitzgerald <fitzgen@gmail.com>
Thu, 13 Oct 2016 16:12:42 -0700
changeset 317931 7c2bcc67e9079970fa9086adbce66af0b99ff74f
parent 317930 711480e99c8cf22931927c88a582a9e3ac54290c
child 317932 a15521c1e84ffabb1cbedb6a93e494eb13c99054
push id33170
push usercbook@mozilla.com
push dateFri, 14 Oct 2016 10:37:07 +0000
treeherderautoland@0d101ebfd95c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssfink
bugs1277338
milestone52.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1277338 - Part 1: Turn js/src into the mozjs-sys crate; r=sfink
.cargo/.gitignore
js/src/.gitignore
js/src/Cargo.lock
js/src/Cargo.toml
js/src/build.rs
js/src/lib.rs
js/src/make-source-package.sh
taskcluster/ci/spidermonkey/kind.yml
taskcluster/scripts/builder/build-sm-mozjs-crate.sh
taskcluster/taskgraph/transforms/gecko_v2_whitelist.py
taskcluster/taskgraph/transforms/job/spidermonkey.py
taskcluster/taskgraph/try_option_syntax.py
new file mode 100644
--- /dev/null
+++ b/.cargo/.gitignore
@@ -0,0 +1,1 @@
+config
new file mode 100644
--- /dev/null
+++ b/js/src/.gitignore
@@ -0,0 +1,1 @@
+target/
new file mode 100644
--- /dev/null
+++ b/js/src/Cargo.lock
@@ -0,0 +1,38 @@
+[root]
+name = "mozjs_sys"
+version = "0.0.0"
+dependencies = [
+ "libc 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libz-sys 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "gcc"
+version = "0.3.35"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "libc"
+version = "0.2.16"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "libz-sys"
+version = "1.0.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "gcc 0.3.35 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libc 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)",
+ "pkg-config 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "pkg-config"
+version = "0.3.8"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[metadata]
+"checksum gcc 0.3.35 (registry+https://github.com/rust-lang/crates.io-index)" = "91ecd03771effb0c968fd6950b37e89476a578aaf1c70297d8e92b6516ec3312"
+"checksum libc 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)" = "408014cace30ee0f767b1c4517980646a573ec61a57957aeeabcac8ac0a02e8d"
+"checksum libz-sys 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "40f2df7730b5d29426c3e44ce4d088d8c5def6471c2c93ba98585b89fb201ce6"
+"checksum pkg-config 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "8cee804ecc7eaf201a4a207241472cc870e825206f6c031e3ee2a72fa425f2fa"
new file mode 100644
--- /dev/null
+++ b/js/src/Cargo.toml
@@ -0,0 +1,18 @@
+[package]
+name = "mozjs_sys"
+version = "0.0.0"
+authors = ["Mozilla"]
+links = "mozjs"
+build = "build.rs"
+
+[features]
+debugmozjs = []
+promises = []
+
+[lib]
+name = "mozjs_sys"
+path = "lib.rs"
+
+[dependencies]
+libc = "0.2"
+libz-sys = "1.0"
new file mode 100644
--- /dev/null
+++ b/js/src/build.rs
@@ -0,0 +1,53 @@
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+use std::env;
+use std::process::{Command, Stdio};
+
+fn main() {
+    let out_dir = env::var("OUT_DIR").expect("Should have env var OUT_DIR");
+    let target = env::var("TARGET").expect("Should have env var TARGET");
+
+    let js_src = env::var("CARGO_MANIFEST_DIR").expect("Should have env var CARGO_MANIFEST_DIR");
+
+    env::set_current_dir(&js_src).unwrap();
+
+    let variant = if cfg!(feature = "debugmozjs") {
+        "plaindebug"
+    } else {
+        "plain"
+    };
+
+    let python = env::var("PYTHON").unwrap_or("python2.7".into());
+    let mut cmd = Command::new(&python);
+    cmd.args(&["./devtools/automation/autospider.py",
+               "--build-only",
+               "--objdir", &out_dir,
+               variant])
+        .env("SOURCE", &js_src)
+        .env("PWD", &js_src)
+        .env("AUTOMATION", "1")
+        .stdout(Stdio::inherit())
+        .stderr(Stdio::inherit());
+    println!("Running command: {:?}", cmd);
+    let result = cmd
+        .status()
+        .expect("Should spawn autospider OK");
+    assert!(result.success(), "autospider should exit OK");
+
+    println!("cargo:rustc-link-search=native={}/js/src", out_dir);
+
+    if target.contains("windows") {
+        println!("cargo:rustc-link-lib=winmm");
+        println!("cargo:rustc-link-lib=psapi");
+        if target.contains("gnu") {
+            println!("cargo:rustc-link-lib=stdc++");
+        }
+    } else {
+        println!("cargo:rustc-link-lib=stdc++");
+    }
+
+    println!("cargo:rustc-link-lib=static=js_static");
+    println!("cargo:outdir={}", out_dir);
+}
new file mode 100644
--- /dev/null
+++ b/js/src/lib.rs
@@ -0,0 +1,2 @@
+extern crate libz_sys;
+
--- a/js/src/make-source-package.sh
+++ b/js/src/make-source-package.sh
@@ -96,16 +96,17 @@ case $cmd in
     ${MKDIR} -p ${tgtpath}/.cargo
     cp -pPR ${TOPSRCDIR}/.cargo/config.in ${tgtpath}/.cargo
 
     # put in js itself
     cp -pPR ${TOPSRCDIR}/mfbt ${tgtpath}
     cp -p ${SRCDIR}/../moz.configure ${tgtpath}/js
     cp -pPR ${SRCDIR}/../public ${tgtpath}/js
     cp -pPR ${SRCDIR}/../examples ${tgtpath}/js
+    cp -pPR ${SRCDIR}/../rust ${tgtpath}/js
     find ${SRCDIR} -mindepth 1 -maxdepth 1 -not -path ${STAGING} -a -not -name ${pkg} \
         -exec cp -pPR {} ${tgtpath}/js/src \;
 
     cp -pPR \
         ${TOPSRCDIR}/python \
         ${tgtpath}
     ${MKDIR} -p ${tgtpath}/dom/bindings
     cp -pPR \
--- a/taskcluster/ci/spidermonkey/kind.yml
+++ b/taskcluster/ci/spidermonkey/kind.yml
@@ -63,16 +63,31 @@ jobs:
                 - nsprpub/**
                 - python/**
                 - taskcluster/moz.build
                 - testing/mozbase/**
                 - test.mozbuild
                 - toolkit/mozapps/installer/package-name.mk
                 - toolkit/mozapps/installer/upload-files.mk
 
+    sm-mozjs-sys/debug:
+        description: "Build js/src as the mozjs_sys Rust crate"
+        index:
+            job-name:
+                gecko-v2: sm-mozjs-sys-debug
+        treeherder:
+            symbol: SM-tc(mozjs-crate)
+        run:
+            using: spidermonkey-mozjs-crate
+            spidermonkey-variant: plain
+        run-on-projects:
+            - integration
+            - release
+            - try
+
     sm-plain/debug:
         description: "Spidermonkey Plain"
         index:
             job-name:
                 buildbot: sm-plain
                 gecko-v2: sm-plaindebug-debug
         treeherder:
             platform: linux64/debug
new file mode 100755
--- /dev/null
+++ b/taskcluster/scripts/builder/build-sm-mozjs-crate.sh
@@ -0,0 +1,18 @@
+#!/usr/bin/env bash
+
+set -xe
+
+source $(dirname $0)/sm-tooltool-config.sh
+
+# Ensure that we have a .config/cargo that points us to our vendored crates
+# rather than to crates.io.
+cd "$SRCDIR/.cargo"
+sed -e "s|@top_srcdir@|$SRCDIR|" < config.in | tee config
+
+cd "$SRCDIR/js/src"
+
+export PATH="$PATH:$TOOLTOOL_CHECKOUT/cargo/bin:$TOOLTOOL_CHECKOUT/rustc/bin"
+export RUST_BACKTRACE=1
+
+cargo build --verbose --frozen --features debugmozjs
+cargo build --verbose --frozen
--- a/taskcluster/taskgraph/transforms/gecko_v2_whitelist.py
+++ b/taskcluster/taskgraph/transforms/gecko_v2_whitelist.py
@@ -50,16 +50,17 @@ JOB_NAME_WHITELIST = set([
     'mulet-opt',
     'nexus-5-l-eng-debug',
     'nexus-5-l-eng-opt',
     'shell-haz-debug',
     'sm-arm64-sim-debug',
     'sm-arm-sim-debug',
     'sm-asan-opt',
     'sm-compacting-debug',
+    'sm-mozjs-sys-debug',
     'sm-msan-opt',
     'sm-nonunified-debug',
     'sm-package-opt',
     'sm-plaindebug-debug',
     'sm-plain-opt',
     'sm-rootanalysis-debug',
     'sm-tsan-opt',
     'win32-debug',
--- a/taskcluster/taskgraph/transforms/job/spidermonkey.py
+++ b/taskcluster/taskgraph/transforms/job/spidermonkey.py
@@ -12,29 +12,30 @@ from voluptuous import Schema, Required,
 
 from taskgraph.transforms.job import run_job_using
 from taskgraph.transforms.job.common import (
     docker_worker_add_public_artifacts,
     docker_worker_support_vcs_checkout,
 )
 
 sm_run_schema = Schema({
-    Required('using'): Any('spidermonkey', 'spidermonkey-package'),
+    Required('using'): Any('spidermonkey', 'spidermonkey-package', 'spidermonkey-mozjs-crate'),
 
     # The SPIDERMONKEY_VARIANT
     Required('spidermonkey-variant'): basestring,
 
     # The tooltool manifest to use; default from sm-tooltool-config.sh  is used
     # if omitted
     Optional('tooltool-manifest'): basestring,
 })
 
 
 @run_job_using("docker-worker", "spidermonkey")
 @run_job_using("docker-worker", "spidermonkey-package")
+@run_job_using("docker-worker", "spidermonkey-mozjs-crate")
 def docker_worker_spidermonkey(config, job, taskdesc, schema=sm_run_schema):
     run = job['run']
 
     worker = taskdesc['worker']
     worker['artifacts'] = []
     worker['caches'] = []
 
     if int(config.params['level']) > 1:
@@ -66,16 +67,18 @@ def docker_worker_spidermonkey(config, j
     if run.get('tooltool-manifest'):
         env['TOOLTOOL_MANIFEST'] = run['tooltool-manifest']
 
     docker_worker_support_vcs_checkout(config, job, taskdesc)
 
     script = "build-sm.sh"
     if run['using'] == 'spidermonkey-package':
         script = "build-sm-package.sh"
+    elif run['using'] == 'spidermonkey-mozjs-crate':
+        script = "build-sm-mozjs-crate.sh"
 
     worker['command'] = [
         '/home/worker/bin/run-task',
         '--chown-recursive', '/home/worker/workspace',
         '--chown-recursive', '/home/worker/tooltool-cache',
         '--vcs-checkout', '/home/worker/workspace/build/src',
         '--',
         '/bin/bash',
--- a/taskcluster/taskgraph/try_option_syntax.py
+++ b/taskcluster/taskgraph/try_option_syntax.py
@@ -159,16 +159,17 @@ RIDEALONG_BUILDS = {
         'sm-nonunified',
         'sm-arm-sim',
         'sm-arm64-sim',
         'sm-compacting',
         'sm-rootanalysis',
         'sm-package',
         'sm-tsan',
         'sm-asan',
+        'sm-mozjs-sys',
         'sm-msan',
     ],
 }
 
 TEST_CHUNK_SUFFIX = re.compile('(.*)-([0-9]+)$')
 
 
 class TryOptionSyntax(object):