diff --git a/.cargo/.gitignore b/.cargo/.gitignore new file mode 100644 index 000000000000..04204c7c9d0e --- /dev/null +++ b/.cargo/.gitignore @@ -0,0 +1 @@ +config diff --git a/js/src/.gitignore b/js/src/.gitignore new file mode 100644 index 000000000000..2f7896d1d136 --- /dev/null +++ b/js/src/.gitignore @@ -0,0 +1 @@ +target/ diff --git a/js/src/Cargo.lock b/js/src/Cargo.lock new file mode 100644 index 000000000000..45046786808d --- /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" diff --git a/js/src/Cargo.toml b/js/src/Cargo.toml new file mode 100644 index 000000000000..0179e0943bfc --- /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" diff --git a/js/src/build.rs b/js/src/build.rs new file mode 100644 index 000000000000..d4e1082321f2 --- /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); +} diff --git a/js/src/lib.rs b/js/src/lib.rs new file mode 100644 index 000000000000..d8f6ce78db7e --- /dev/null +++ b/js/src/lib.rs @@ -0,0 +1,2 @@ +extern crate libz_sys; + diff --git a/js/src/make-source-package.sh b/js/src/make-source-package.sh index b0c08e4a6cff..6a334ec4dd7f 100755 --- a/js/src/make-source-package.sh +++ b/js/src/make-source-package.sh @@ -101,6 +101,7 @@ case $cmd in 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 \; diff --git a/taskcluster/ci/spidermonkey/kind.yml b/taskcluster/ci/spidermonkey/kind.yml index bc3ef89e8059..9e8f9a682a5b 100644 --- a/taskcluster/ci/spidermonkey/kind.yml +++ b/taskcluster/ci/spidermonkey/kind.yml @@ -68,6 +68,21 @@ jobs: - 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: diff --git a/taskcluster/scripts/builder/build-sm-mozjs-crate.sh b/taskcluster/scripts/builder/build-sm-mozjs-crate.sh new file mode 100755 index 000000000000..09c353084d0a --- /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 diff --git a/taskcluster/taskgraph/transforms/gecko_v2_whitelist.py b/taskcluster/taskgraph/transforms/gecko_v2_whitelist.py index 9e8efa0896b0..4c099346444f 100644 --- a/taskcluster/taskgraph/transforms/gecko_v2_whitelist.py +++ b/taskcluster/taskgraph/transforms/gecko_v2_whitelist.py @@ -55,6 +55,7 @@ JOB_NAME_WHITELIST = set([ 'sm-arm-sim-debug', 'sm-asan-opt', 'sm-compacting-debug', + 'sm-mozjs-sys-debug', 'sm-msan-opt', 'sm-nonunified-debug', 'sm-package-opt', diff --git a/taskcluster/taskgraph/transforms/job/spidermonkey.py b/taskcluster/taskgraph/transforms/job/spidermonkey.py index 83ff7f03dc76..89f7e164f11d 100644 --- a/taskcluster/taskgraph/transforms/job/spidermonkey.py +++ b/taskcluster/taskgraph/transforms/job/spidermonkey.py @@ -17,7 +17,7 @@ from taskgraph.transforms.job.common import ( ) 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, @@ -30,6 +30,7 @@ sm_run_schema = Schema({ @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'] @@ -71,6 +72,8 @@ def docker_worker_spidermonkey(config, job, taskdesc, schema=sm_run_schema): 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', diff --git a/taskcluster/taskgraph/try_option_syntax.py b/taskcluster/taskgraph/try_option_syntax.py index e8d6924872a1..409d75b42f55 100644 --- a/taskcluster/taskgraph/try_option_syntax.py +++ b/taskcluster/taskgraph/try_option_syntax.py @@ -164,6 +164,7 @@ RIDEALONG_BUILDS = { 'sm-package', 'sm-tsan', 'sm-asan', + 'sm-mozjs-sys', 'sm-msan', ], }