Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[msvc] Support MSVC 12/14 bindings generation and builds #270

Merged
merged 3 commits into from Aug 9, 2016
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -1,5 +1,6 @@
libmozjs.so
*~
vc*.pdb
js
/doc
/target
@@ -0,0 +1,35 @@
project(rust-mozjs)
cmake_minimum_required(VERSION 2.6)

set(DUMMY ${CMAKE_BUILD_TYPE})

set(SOURCES
src/jsglue.cpp
)

include_directories($ENV{DEP_MOZJS_OUTDIR}/dist/include)

if(MSVC)
if(NOT "$ENV{CARGO_FEATURE_DEBUGMOZJS}" STREQUAL "")
add_definitions(-MDd -Od -DDEBUG -D_DEBUG)
else()
add_definitions(-MD)
endif()
add_definitions(-FI$ENV{DEP_MOZJS_OUTDIR}/js/src/js-confdefs.h)
add_definitions(-DWIN32)
add_definitions(-Zi -GR-)
else()
if(NOT "$ENV{CARGO_FEATURE_DEBUGMOZJS}" STREQUAL "")
add_definitions(-g -O0 -DDEBUG -D_DEBUG)
endif()
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_definitions(-Wno-c++0x-extensions -Wno-return-type-c-linkage -Wno-invalid-offsetof)
endif()
add_definitions(-fPIC -fno-rtti)
add_definitions(-std=c++11 -DJS_NO_JSVAL_JSID_STRUCT_TYPES)
add_definitions(-include $ENV{DEP_MOZJS_OUTDIR}/js/src/js-confdefs.h)
endif()

add_library(jsglue STATIC ${SOURCES})
install(TARGETS jsglue ARCHIVE DESTINATION lib)

@@ -3,9 +3,11 @@
name = "js"
version = "0.1.3"
authors = ["The Servo Project Developers"]

build = "build.rs"

[build-dependencies]
cmake = "0.1"

[[test]]
name = "callback"
[[test]]
@@ -1,28 +1,71 @@
version: 1.0.{build}

environment:
PATH: 'C:\msys64\mingw64\bin;C:\msys64\usr\bin\;%PATH%'
MSYSTEM: 'MSYS'
MSYS: 'winsymlinks=lnk'
TARGET: 'nightly-x86_64-pc-windows-gnu'
# The appveyor image we use has a pretty huge set of things installed... we make the
# initial PATH something sane so we know what to expect
PATH: "C:\\windows\\system32;\
C:\\windows;\
C:\\windows\\System32\\Wbem;\
C:\\windows\\System32\\WindowsPowerShell\\v1.0;\
C:\\ProgramData\\chocolatey\\bin;\
C:\\Python27;\
C:\\Tools\\PsTools;\
C:\\Tools\\NuGet3;\
C:\\Program Files\\Microsoft\\Web Platform Installer\\;\
C:\\Program Files\\7-Zip;\
C:\\Program Files\\Mercurial;\
C:\\Program Files (x86)\\Subversion\\bin;\
C:\\Program Files (x86)\\CMake\\bin;\
C:\\Program Files (x86)\\Windows Kits\\10\\Windows Performance Toolkit\\;\
C:\\Program Files (x86)\\MSBuild\\14.0\\Bin;\
C:\\Program Files\\Amazon\\AWSCLI\\;\
C:\\Program Files\\Microsoft Windows Performance Toolkit\\;\
C:\\Program Files\\LLVM\\bin;\
C:\\Program Files\\Git LFS;\
C:\\Program Files\\Git\\cmd;\
C:\\Program Files\\Git\\usr\\bin;\
C:\\Program Files\\AppVeyor\\BuildAgent;"
matrix:
- TARGET: nightly-x86_64-pc-windows-msvc
- TARGET: nightly-x86_64-pc-windows-gnu

platform:
- x64
# Uncomment to enable RDP & wait for exit. Connection info will be printed in the log.
#init:
# - ps: iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1'))
#on_finish:
# - ps: $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1'))

# called after cloning, before building
install:
- bash -lc "echo $MSYSTEM; pacman --needed --noconfirm -Sy pacman-mirrors"
- bash -lc "pacman --noconfirm -Sy"
- bash -lc "pacman -Sy --needed --noconfirm git mingw-w64-x86_64-toolchain tar make python2-setuptools"
- bash -lc "easy_install-2.7 pip virtualenv"
- bash -lc "mv /mingw64/bin/python2.exe /mingw64/bin/python2-mingw64.exe"
- bash -lc "mv /mingw64/bin/python2.7.exe /mingw64/bin/python2.7-mingw64.exe"
- ps: Start-FileDownload "http://servo-rust.s3.amazonaws.com/build/MozillaBuildSetup-2.2.0.exe"
- ps: .\MozillaBuildSetup-2.2.0.exe /S | Out-Null
- ps: Start-FileDownload "https://static.rust-lang.org/dist/rust-${env:TARGET}.exe" -FileName "rust-install.exe"
- ps: .\rust-install.exe /VERYSILENT /NORESTART /DIR="C:\rust" | Out-Null
- ps: $env:PATH="$env:PATH;C:\rust\bin"
# I can't make this work with a multi-line script (e.g. via |+ etc.), so we copy the if before every command
- if %TARGET:*-msvc=msvc%==msvc set BUILD_ENV=msvc
- if %TARGET:*-gnu=gnu%==gnu set BUILD_ENV=gnu
- if %BUILD_ENV%==msvc call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\amd64\vcvars64.bat"
- if %BUILD_ENV%==msvc copy C:\mozilla-build\yasm\yasm.exe C:\mozilla-build\msys\bin
- if %BUILD_ENV%==msvc copy C:\mozilla-build\mozmake\mozmake.exe C:\mozilla-build\msys\bin
- if %BUILD_ENV%==msvc set MOZTOOLS_PATH=C:\mozilla-build\msys\bin
- if %BUILD_ENV%==msvc set NATIVE_WIN32_PYTHON=C:/Python27/python.exe
- if %BUILD_ENV%==gnu set PATH=C:\msys64\mingw64\bin;C:\msys64\usr\bin\;%PATH%
- if %BUILD_ENV%==gnu set MSYSTEM=MINGW64
- if %BUILD_ENV%==gnu set MSYS=winsymlinks=lnk
- if %BUILD_ENV%==gnu bash -lc "echo $MSYSTEM; pacman --needed --noconfirm -Sy pacman-mirrors"
- if %BUILD_ENV%==gnu bash -lc "pacman --noconfirm -Sy"
- if %BUILD_ENV%==gnu bash -lc "pacman -Sy --needed --noconfirm git mingw-w64-x86_64-toolchain tar make python2-setuptools"
- if %BUILD_ENV%==gnu bash -lc "easy_install-2.7 pip virtualenv"
- if %BUILD_ENV%==gnu bash -lc "mv /mingw64/bin/python2.exe /mingw64/bin/python2-mingw64.exe"
- if %BUILD_ENV%==gnu bash -lc "mv /mingw64/bin/python2.7.exe /mingw64/bin/python2.7-mingw64.exe"
- rustc -vV
- cargo -vV

build_script:
- cmd: >-
set MSYSTEM=MINGW64
- echo PATH %PATH%
- echo VSINSTALLDIR %VSINSTALLDIR%
- echo MOZTOOLS_PATH %MOZTOOLS_PATH%
- if %BUILD_ENV%==msvc cd %APPVEYOR_BUILD_FOLDER% && cargo build && cargo test
- if %BUILD_ENV%==gnu bash -lc "cd $APPVEYOR_BUILD_FOLDER; cargo build && cargo test"

bash -lc "cd $APPVEYOR_BUILD_FOLDER; cargo build && cargo test"
@@ -2,17 +2,10 @@
* 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};
extern crate cmake;

fn main() {
let result = Command::new("make")
.args(&["-R", "-f", "makefile.cargo"])
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.status()
.unwrap();
assert!(result.success());
println!("cargo:rustc-link-search=native={}", env::var("OUT_DIR").unwrap());
let dst = cmake::Config::new(".").build();
println!("cargo:rustc-link-search=native={}/lib", dst.display());
println!("cargo:rustc-link-lib=static=jsglue");
}
@@ -0,0 +1,44 @@
Building bindings requires rust-bindgen checked out and built in ../../rust-bindgen
(it expects to find the binary in ../../rust-bindgen/target/debug/bindgen).

=== Windows ===

rust-bindgen must be built using a rust for the pc-windows-gnu target, not msvc, even
when generating msvc bindings. Within a MINGW64 env, install mingw-w64-x86_64-clang
then build rust-bindgen with 'LIBCLANG_PATH=c:/msys64/mingw64/bin cargo build' (replace
c:/msys64 with the root of your msys2-64 install directory).

==== MSVC bindings ====

Now, build rust-mozjs using a pc-windows-msvc rust. Note that you'll need to be in an
environment that has the Visual C++ env vars already set up for your compiler -- the msys
package http://people.mozilla.org/~vladimir/misc/moz-vs-0.1.2-any.pkg.tar.xz can help
with this (install with pacman -U moz-vs-0.1.2-any.pkg.tar.xz). After installation, running
"moz_vs" will set up env vars for the current shell for the given target (2015 or 2013).
This command is additive to the env -- it doesn't "switch", a new shell is required to use
a different compiler.

To generate VC14 (VS2015) bindings, in rust-mozjs:

moz_vs 2015
cargo build
[wait for everything to build; if bindings are out of date, it'll error out at the end -- that's okay]
./etc/bindings.sh msvc14
cp out.rs src/jsapi_windows_msvc14_64.rs
cargo build # make sure the build finishes

The debug bindings:

cargo clean
cargo build --features debugmozjs
[wait for everything to build]
./etc/bindings.sh msvc14
cp out.rs src/jsapi_windows_msvc14_64_debug.rs
cargo build --features debugmozjs

If you get errors about "static_assert expression is not an integral constant expression",
additional static_assert(offsetof(...)) sites need to be #if 0'd out (this ends up being
a non-constant-expression according to clang when built with the MSVC headers).

For generating the bindings with MSVC, only MSVC 2013 and 2015 are
supported (VC12 and 14). Run 'bindings.sh msvc12' and/or 'bindings.sh msvc14'.
@@ -1,6 +1,17 @@
#!/bin/bash

cd "$(dirname "$0")"

EXTRA_FLAGS=
if [[ "$1" == "msvc14" ]] ; then
EXTRA_FLAGS="-use-msvc-mangling --target=x86_64-pc-win32 -DWIN32=1"
EXTRA_FLAGS="$EXTRA_FLAGS -fms-compatibility-version=19.00"
EXTRA_FLAGS="$EXTRA_FLAGS -DEXPORT_JS_API=1 -D_CRT_USE_BUILTIN_OFFSETOF"
EXTRA_FLAGS="$EXTRA_FLAGS -fvisibility=hidden"
fi

../../rust-bindgen/target/debug/bindgen \
${EXTRA_FLAGS} \
-no-class-constants \
-no-type-renaming \
-dtor-attr unsafe_no_drop_flag \
@@ -15,6 +26,7 @@ cd "$(dirname "$0")"
-blacklist-type HashTableEntry \
-blacklist-type AutoStableStringChars \
-blacklist-type ErrorReport \
-blacklist-type MemProfiler \
-opaque-type RuntimeStats \
-opaque-type EnumeratedArray \
-opaque-type HashMap \
@@ -1,5 +1,7 @@
#include <stdint.h>
#ifndef _MSC_VER
#include <unistd.h>
#endif

typedef uint32_t HashNumber;

This file was deleted.

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.