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 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Next

Support MSVC14 (VS2015) bindings generation and builds

  • Loading branch information
vvuk committed Aug 2, 2016
commit dc5652899658f739c4f2fc16d433309e21213231
@@ -1,5 +1,6 @@
libmozjs.so
*~
vc*.pdb
js
/doc
/target
@@ -4,10 +4,9 @@ environment:
PATH: 'C:\msys64\mingw64\bin;C:\msys64\usr\bin\;%PATH%'
MSYSTEM: 'MSYS'
MSYS: 'winsymlinks=lnk'
TARGET: 'nightly-x86_64-pc-windows-gnu'

platform:
- x64
matrix:
- TARGET: nightly-x86_64-pc-windows-msvc
- TARGET: nightly-x86_64-pc-windows-gnu

install:
- bash -lc "echo $MSYSTEM; pacman --needed --noconfirm -Sy pacman-mirrors"
@@ -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;

@@ -1,3 +1,8 @@
ifeq (,$(findstring msvc,$(TARGET)))
#
# non-MSVC build
#

ifneq ($(HOST),$(TARGET))

CXX ?= $(TARGET)-g++
@@ -37,3 +42,35 @@ $(OUT_DIR)/libjsglue.a: $(OUT_DIR)/jsglue.o

$(OUT_DIR)/jsglue.o: src/jsglue.cpp
$(CXX) $(CFLAGS) -fno-rtti $< -o $@ -c

else
#
# MSVC
#
CXX ?= cl -NOLOGO
AR ?= lib -NOLOGO

CFLAGS += -I$(DEP_MOZJS_OUTDIR)/dist/include -FI$(DEP_MOZJS_OUTDIR)/js/src/js-confdefs.h -DWIN32
CFLAGS += -Zi
CFLAGS += -GR-
CFLAGS += -MD

ifneq (,$(CARGO_FEATURE_DEBUGMOZJS))
# Dynamic debug runtime
CFLAGS += -MDd
CFLAGS += -Od -DDEBUG -D_DEBUG
else
# Dynamic non-debug runtime
CFLAGS += -MD
endif

.PHONY: all
all: $(OUT_DIR)/jsglue.lib

$(OUT_DIR)/jsglue.lib: $(OUT_DIR)/jsglue.obj
$(AR) -OUT:$@ $<

$(OUT_DIR)/jsglue.obj: src/jsglue.cpp
$(CXX) $(CFLAGS) $< -Fo: $@ -c

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