Skip to content

Commit d59484d

Browse files
author
bors-servo
authored
Auto merge of #176 - servo:win-cross, r=Manishearth
Support cross-compiling from x64->x86 on Windows. These changes allow building for an x86 target on a x64 host. The changes to the JS glue are an extension of changes we've made in the past for other targets; we have just never run the affected tests for those targets before. <!-- 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/176) <!-- Reviewable:end -->
2 parents 65670f7 + cbadf7f commit d59484d

File tree

8 files changed

+107
-56
lines changed

8 files changed

+107
-56
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "mozjs_sys"
33
description = "System crate for the Mozilla SpiderMonkey JavaScript engine."
44
repository = "https://github.com/servo/mozjs/"
5-
version = "0.61.9"
5+
version = "0.61.10"
66
authors = ["Mozilla"]
77
links = "mozjs"
88
build = "build.rs"

appveyor.yml

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
version: 1.0.{build}
22
image: Visual Studio 2017
33

4+
matrix:
5+
fast_finish: true
6+
47
environment:
58
# The appveyor image we use has a pretty huge set of things installed... we make the
69
# initial PATH something sane so we know what to expect
@@ -27,6 +30,13 @@ environment:
2730
C:\\Program Files\\Git\\usr\\bin;\
2831
C:\\Program Files\\AppVeyor\\BuildAgent;"
2932

33+
VCVARSALL_PATH: C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build
34+
35+
matrix:
36+
- TARGET: i686-pc-windows-msvc
37+
CROSS_COMPILE: 1
38+
- TARGET: x86_64-pc-windows-msvc
39+
3040
# Uncomment to enable RDP & wait for exit. Connection info will be printed in the log.
3141
#init:
3242
# - ps: iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1'))
@@ -36,13 +46,12 @@ environment:
3646
# called after cloning, before building
3747
install:
3848
- set BUILD_ENV=msvc
39-
- set TARGET=nightly-x86_64-pc-windows-msvc
4049
- ps: Start-FileDownload "http://servo-rust.s3.amazonaws.com/build/MozillaBuildSetup-2.2.0.exe"
4150
- ps: .\MozillaBuildSetup-2.2.0.exe /S | Out-Null
42-
- ps: Start-FileDownload "https://static.rust-lang.org/dist/rust-${env:TARGET}.exe" -FileName "rust-install.exe"
43-
- ps: .\rust-install.exe /VERYSILENT /NORESTART /DIR="C:\rust" | Out-Null
44-
- ps: $env:PATH="$env:PATH;C:\rust\bin"
45-
- call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat"
51+
- appveyor-retry appveyor DownloadFile https://win.rustup.rs/ -FileName rustup-init.exe
52+
- rustup-init.exe -y --default-host=x86_64-pc-windows-msvc
53+
- set PATH=%PATH%;C:\Users\appveyor\.cargo\bin
54+
- if "%CROSS_COMPILE%" == "1" rustup target add %TARGET%
4655
- set MOZTOOLS_PATH=C:\mozilla-build\msys\bin;C:\mozilla-build\mozmake;C:\mozilla-build\yasm
4756
- set NATIVE_WIN32_PYTHON=C:/Python27/python.exe
4857
- set AUTOCONF=C:/mozilla-build/msys/local/bin/autoconf-2.13
@@ -51,6 +60,7 @@ install:
5160

5261
build_script:
5362
- echo PATH %PATH%
54-
- echo VSINSTALLDIR %VSINSTALLDIR%
5563
- echo MOZTOOLS_PATH %MOZTOOLS_PATH%
56-
- cd %APPVEYOR_BUILD_FOLDER% && cargo build --verbose --verbose && cargo test --lib
64+
- cd %APPVEYOR_BUILD_FOLDER%
65+
- if "%CROSS_COMPILE%" == "" call "%VCVARSALL_PATH%\vcvars64.bat"
66+
- cargo test --verbose --verbose --target %TARGET% --lib

build.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,42 @@ use std::env;
99
use std::path::PathBuf;
1010
use std::ffi::{OsStr, OsString};
1111
use std::process::{Command, Stdio};
12+
use std::str;
1213

1314
fn main() {
1415
let target = env::var("TARGET").unwrap();
16+
let host = env::var("HOST").unwrap();
1517
if env::var_os("CARGO_FEATURE_DEBUGMOZJS").is_some() && target.contains("windows") {
1618
// https://github.com/rust-lang/rust/issues/39016
1719
panic!("Rustc doesn't support MSVC debug runtime.");
1820
}
1921

22+
if target.contains("windows") && host != target {
23+
assert_eq!(host, "x86_64-pc-windows-msvc",
24+
"Only cross-compiling from x64 is supported");
25+
assert_eq!(target, "i686-pc-windows-msvc",
26+
"Only cross-compiling to x86 is supported");
27+
assert!(env::var("VSINSTALLDIR").is_err());
28+
// When cross-compiling on Windows, we need to ensure that the PATH is
29+
// set up appropriately for the target before invoking make.
30+
if env::var("VCVARSALL_PATH").is_err() {
31+
panic!("Need to provide VCVARSALL_PATH value with path to \
32+
vcvarsall.bat from Visual Studio installation");
33+
}
34+
35+
let vcvars = Command::new("vcvars.bat").output().unwrap();
36+
assert!(vcvars.status.success());
37+
let output = str::from_utf8(&vcvars.stdout).unwrap();
38+
for line in output.lines() {
39+
let mut parts = line.splitn(2, '=');
40+
if let Some(name) = parts.next() {
41+
if let Some(value) = parts.next() {
42+
env::set_var(name, value);
43+
}
44+
}
45+
}
46+
}
47+
2048
build_jsapi();
2149
build_jsglue();
2250
build_jsapi_bindings();
@@ -319,6 +347,7 @@ const OPAQUE_TYPES: &'static [&'static str] = &[
319347
"mozilla::Maybe.*",
320348
"mozilla::UniquePtr.*",
321349
"mozilla::Variant",
350+
"RefPtr_Proxy.*",
322351
];
323352

324353
/// Types for which we should NEVER generate bindings, even if it is used within

makefile.cargo

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ CONFIGURE_FLAGS := \
1010
--disable-shared-js \
1111
--build-backends=RecursiveMake
1212

13+
ifeq (windows,$(findstring windows,$(TARGET)))
14+
WINDOWS := 1
15+
else
16+
WINDOWS :=
17+
endif
18+
1319
ifneq ($(HOST),$(TARGET))
1420

1521
ifeq (armv7-linux-androideabi,$(TARGET))
@@ -55,16 +61,17 @@ ifneq ($(HOST),$(TARGET))
5561
endif
5662
endif
5763

58-
CC ?= $(TARGET)-gcc
59-
CPP ?= $(TARGET)-gcc -E
60-
CXX ?= $(TARGET)-g++
61-
AR ?= $(TARGET)-ar
62-
63-
CONFIGURE_FLAGS += --target=$(TARGET) --disable-gold
64+
ifeq ($(WINDOWS),)
65+
CC ?= $(TARGET)-gcc
66+
CPP ?= $(TARGET)-gcc -E
67+
CXX ?= $(TARGET)-g++
68+
AR ?= $(TARGET)-ar
69+
CONFIGURE_FLAGS += --target=$(TARGET) --disable-gold
70+
endif
6471

6572
else
6673

67-
ifeq (,$(VCINSTALLDIR))
74+
ifeq (,$(WINDOWS))
6875
ifeq (freebsd,$(findstring freebsd,$(TARGET)))
6976
# Does not symlink clang as "gcc" like macOS does
7077
CC ?= clang
@@ -100,7 +107,7 @@ ifneq (,$(CCACHE))
100107
CONFIGURE_FLAGS += --with-ccache=$(CCACHE)
101108
endif
102109

103-
ifneq ($(VCINSTALLDIR),)
110+
ifneq ($(WINDOWS),)
104111
# Visual Studio build
105112
NEED_WIN_PYTHON := 1
106113

@@ -111,6 +118,9 @@ ifneq ($(VCINSTALLDIR),)
111118
ifeq ($(findstring x86_64,$(TARGET)),x86_64)
112119
# This is the correct target for MSVC builds
113120
CONFIGURE_FLAGS += --target=x86_64-pc-mingw32 --host=x86_64-pc-mingw32
121+
else ifeq ($(findstring i686,$(TARGET)),i686)
122+
# This is the correct target for MSVC builds
123+
CONFIGURE_FLAGS += --target=i686-pc-mingw32 --host=i686-pc-mingw32
114124
endif
115125
CONFIGURE_FLAGS += --without-pthreads
116126
MOZ_TOOLS=/

src/jsglue.cpp

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -62,55 +62,55 @@ void JS_ValueSetBoolean(JS::Value* value, bool x) {
6262
value->setBoolean(x);
6363
}
6464

65-
bool JS_ValueIsBoolean(JS::Value value) {
66-
return value.isBoolean();
65+
bool JS_ValueIsBoolean(const JS::Value* value) {
66+
return value->isBoolean();
6767
}
6868

69-
bool JS_ValueToBoolean(JS::Value value) {
70-
return value.toBoolean();
69+
bool JS_ValueToBoolean(const JS::Value* value) {
70+
return value->toBoolean();
7171
}
7272

7373
void JS_ValueSetDouble(JS::Value* value, double x) {
7474
value->setDouble(x);
7575
}
7676

77-
bool JS_ValueIsDouble(JS::Value value) {
78-
return value.isDouble();
77+
bool JS_ValueIsDouble(const JS::Value* value) {
78+
return value->isDouble();
7979
}
8080

81-
double JS_ValueToDouble(JS::Value value) {
82-
return value.toDouble();
81+
double JS_ValueToDouble(const JS::Value* value) {
82+
return value->toDouble();
8383
}
8484

8585
void JS_ValueSetInt32(JS::Value* value, int32_t x) {
8686
value->setInt32(x);
8787
}
8888

89-
bool JS_ValueIsInt32(JS::Value value) {
90-
return value.isInt32();
89+
bool JS_ValueIsInt32(const JS::Value* value) {
90+
return value->isInt32();
9191
}
9292

93-
int32_t JS_ValueToInt32(JS::Value value) {
94-
return value.toInt32();
93+
int32_t JS_ValueToInt32(const JS::Value* value) {
94+
return value->toInt32();
9595
}
9696

97-
bool JS_ValueIsNumber(JS::Value value) {
98-
return value.isNumber();
97+
bool JS_ValueIsNumber(const JS::Value* value) {
98+
return value->isNumber();
9999
}
100100

101-
double JS_ValueToNumber(JS::Value value) {
102-
return value.toNumber();
101+
double JS_ValueToNumber(const JS::Value* value) {
102+
return value->toNumber();
103103
}
104104

105105
void JS_ValueSetNull(JS::Value* value) {
106106
value->setNull();
107107
}
108108

109-
bool JS_ValueIsNull(JS::Value value) {
110-
return value.isNull();
109+
bool JS_ValueIsNull(const JS::Value* value) {
110+
return value->isNull();
111111
}
112112

113-
bool JS_ValueIsUndefined(JS::Value value) {
114-
return value.isUndefined();
113+
bool JS_ValueIsUndefined(const JS::Value* value) {
114+
return value->isUndefined();
115115
}
116116
}

src/jsglue.hpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,24 +34,24 @@ JS::shadow::Zone* JS_AsShadowZone(JS::Zone* zone);
3434
JS::CallArgs JS_CallArgsFromVp(unsigned argc, JS::Value* vp);
3535

3636
void JS_ValueSetBoolean(JS::Value* value, bool x);
37-
bool JS_ValueIsBoolean(JS::Value value);
38-
bool JS_ValueToBoolean(JS::Value value);
37+
bool JS_ValueIsBoolean(const JS::Value* value);
38+
bool JS_ValueToBoolean(const JS::Value* value);
3939

4040
void JS_ValueSetDouble(JS::Value* value, double x);
41-
bool JS_ValueIsDouble(JS::Value value);
42-
double JS_ValueToDouble(JS::Value value);
41+
bool JS_ValueIsDouble(const JS::Value* value);
42+
double JS_ValueToDouble(const JS::Value* value);
4343

4444
void JS_ValueSetInt32(JS::Value* value, int32_t x);
45-
bool JS_ValueIsInt32(JS::Value value);
46-
int32_t JS_ValueToInt32(JS::Value value);
45+
bool JS_ValueIsInt32(const JS::Value* value);
46+
int32_t JS_ValueToInt32(const JS::Value* value);
4747

48-
bool JS_ValueIsNumber(JS::Value value);
49-
double JS_ValueToNumber(JS::Value value);
48+
bool JS_ValueIsNumber(const JS::Value* value);
49+
double JS_ValueToNumber(const JS::Value* value);
5050

5151
void JS_ValueSetNull(JS::Value* value);
52-
bool JS_ValueIsNull(JS::Value value);
52+
bool JS_ValueIsNull(const JS::Value* value);
5353

54-
bool JS_ValueIsUndefined(JS::Value value);
54+
bool JS_ValueIsUndefined(const JS::Value* value);
5555

5656
}
5757

src/jsval.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -545,28 +545,28 @@ fn assert_agreement(val1: JSVal, val2: JSVal) {
545545

546546
assert_eq!(val1.asBits(), val2.asBits());
547547

548-
assert_eq!(unsafe { JS_ValueIsBoolean(val1) }, val2.is_boolean());
548+
assert_eq!(unsafe { JS_ValueIsBoolean(&val1) }, val2.is_boolean());
549549
if val2.is_boolean() {
550-
assert_eq!(unsafe { JS_ValueToBoolean(val1) }, val2.to_boolean());
550+
assert_eq!(unsafe { JS_ValueToBoolean(&val1) }, val2.to_boolean());
551551
}
552552

553-
assert_eq!(unsafe { JS_ValueIsDouble(val1) }, val2.is_double());
553+
assert_eq!(unsafe { JS_ValueIsDouble(&val1) }, val2.is_double());
554554
if val2.is_double() {
555-
assert_eq!(unsafe { JS_ValueToDouble(val1) }, val2.to_double());
555+
assert_eq!(unsafe { JS_ValueToDouble(&val1) }, val2.to_double());
556556
}
557557

558-
assert_eq!(unsafe { JS_ValueIsInt32(val1) }, val2.is_int32());
558+
assert_eq!(unsafe { JS_ValueIsInt32(&val1) }, val2.is_int32());
559559
if val2.is_int32() {
560-
assert_eq!(unsafe { JS_ValueToInt32(val1) }, val2.to_int32());
560+
assert_eq!(unsafe { JS_ValueToInt32(&val1) }, val2.to_int32());
561561
}
562562

563-
assert_eq!(unsafe { JS_ValueIsNumber(val1) }, val2.is_number());
563+
assert_eq!(unsafe { JS_ValueIsNumber(&val1) }, val2.is_number());
564564
if val2.is_number() {
565-
assert_eq!(unsafe { JS_ValueToNumber(val1) }, val2.to_number());
565+
assert_eq!(unsafe { JS_ValueToNumber(&val1) }, val2.to_number());
566566
}
567567

568-
assert_eq!(unsafe { JS_ValueIsNull(val1) }, val2.is_null());
568+
assert_eq!(unsafe { JS_ValueIsNull(&val1) }, val2.is_null());
569569

570-
assert_eq!(unsafe { JS_ValueIsUndefined(val1) }, val2.is_undefined());
570+
assert_eq!(unsafe { JS_ValueIsUndefined(&val1) }, val2.is_undefined());
571571

572572
}

vcvars.bat

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
call "%VCVARSALL_PATH%\vcvarsall.bat" x64_x86
2+
set

0 commit comments

Comments
 (0)