Skip to content

Commit a246f0d

Browse files
committed
NODE-2338 support building addon for windows
This patch includes changes to our binding definitions and the build-static.sh script in order to build the addon for windows users.
1 parent 87fbc56 commit a246f0d

File tree

4 files changed

+124
-67
lines changed

4 files changed

+124
-67
lines changed

.evergreen/config.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ functions:
150150
script: |-
151151
${compile_env|} ./libmongocrypt/.evergreen/build_all.sh
152152
cd ./libmongocrypt/bindings/python && ${test_env|} ./.evergreen/test.sh
153-
153+
154154
"build and test node":
155155
- command: "shell.exec"
156156
params:
@@ -336,7 +336,7 @@ tasks:
336336
commands:
337337
- func: "fetch source"
338338
- func: "build and test java"
339-
339+
340340
- name: build-and-test-python
341341
depends_on:
342342
- variant: ubuntu1804-64
@@ -423,7 +423,7 @@ tasks:
423423
name: build-and-test-and-upload
424424
- variant: suse15-64
425425
name: build-and-test-and-upload
426-
- variant: suse12-s390x
426+
- variant: suse12-s390x
427427
name: build-and-test-and-upload
428428
- variant: ubuntu1604-arm64
429429
name: build-and-test-and-upload
@@ -551,7 +551,7 @@ tasks:
551551
552552
CMAKE=/cygdrive/c/cmake/bin/cmake
553553
mongocrypt_version="$($CMAKE -P ./cmake/GetVersion.cmake 2>&1)"
554-
case "$mongocrypt_version" in
554+
case "$mongocrypt_version" in
555555
*+*)
556556
# Not a tagged release.
557557
echo "{}" > ./.evergreen/windows-upload.json
@@ -687,6 +687,7 @@ buildvariants:
687687
- build-and-test-shared-bson
688688
- build-csharp-and-test
689689
- build-and-test-python
690+
- build-and-test-node
690691
- windows-upload-check
691692
- name: linux-64-amazon-ami
692693
display_name: "Amazon Linux"
@@ -856,7 +857,7 @@ buildvariants:
856857
- name: publish-packages
857858
distros:
858859
- rhel70-small
859-
- name: suse12-s390x
860+
- name: suse12-s390x
860861
display_name: "SLES 12 s390x"
861862
run_on: suse12-zseries-test
862863
expansions:

bindings/node/.evergreen/setup_environment.sh

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22

3-
# set -o xtrace # Write all commands first to stderr
3+
set -o xtrace # Write all commands first to stderr
44
set -o errexit # Exit the script with error if any of the commands fail
55

66
NODE_LTS_NAME=${NODE_LTS_NAME:-dubnium}
@@ -10,6 +10,8 @@ NPM_CACHE_DIR="${NODE_ARTIFACTS_PATH}/npm"
1010
NPM_TMP_DIR="${NODE_ARTIFACTS_PATH}/tmp"
1111
BIN_DIR="$(pwd)/bin"
1212
MONGOCRYPTD_PATH="https://s3.amazonaws.com/mciuploads/mongodb-mongo-v4.2/enterprise-ubuntu1604-64/f92115cad9d2a4c2ddcf3c2c65092dda2fd7147a/binaries/mongo-cryptd-mongodb_mongo_v4.2_enterprise_ubuntu1604_64_f92115cad9d2a4c2ddcf3c2c65092dda2fd7147a_19_06_13_17_31_40.tgz"
13+
NVM_WINDOWS_URL="https://github.com/coreybutler/nvm-windows/releases/download/1.1.7/nvm-noinstall.zip"
14+
NVM_URL="https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh"
1315

1416
# create node artifacts path if needed
1517
mkdir -p ${NODE_ARTIFACTS_PATH}
@@ -21,18 +23,48 @@ mkdir -p ${BIN_DIR}
2123
export PATH="$BIN_DIR:/opt/mongodbtoolchain/v2/bin:$PATH"
2224

2325
# locate cmake
24-
. ./.evergreen/find_cmake.sh
26+
if [ "$OS" == "Windows_NT" ]; then
27+
CMAKE=/cygdrive/c/cmake/bin/cmake
28+
ADDITIONAL_CMAKE_FLAGS="-Thost=x64 -A x64"
29+
else
30+
chmod u+x ./.evergreen/find-cmake.sh
31+
. ./.evergreen/find-cmake.sh
32+
fi
2533

2634
# this needs to be explicitly exported for the nvm install below
2735
export NVM_DIR="${NODE_ARTIFACTS_PATH}/nvm"
2836
mkdir -p ${NVM_DIR}
2937

3038
# install Node.js
31-
echo "Installing NVM"
32-
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bash
33-
[ -s "${NVM_DIR}/nvm.sh" ] && \. "${NVM_DIR}/nvm.sh"
3439
echo "Installing Node ${NODE_LTS_NAME}"
35-
nvm install --lts=${NODE_LTS_NAME}
40+
if [ "$OS" == "Windows_NT" ]; then
41+
# nvm-windows doesn't support lts names, so this will convert them to the latest releases for us
42+
NODE_VERSION=$(curl -s -L https://nodejs.org/dist/latest-${NODE_LTS_NAME}/SHASUMS256.txt | grep -oP 'node-v\K\w+.\w+.\w+' | head -1)
43+
44+
export NVM_HOME=`cygpath -w "$NVM_DIR"`
45+
export NVM_SYMLINK=`cygpath -w "$NODE_ARTIFACTS_PATH/bin"`
46+
export PATH=`cygpath $NVM_SYMLINK`:`cygpath $NVM_HOME`:$PATH
47+
48+
# download and install nvm
49+
curl -L $NVM_WINDOWS_URL -o nvm.zip
50+
unzip -d $NVM_DIR nvm.zip
51+
rm nvm.zip
52+
53+
chmod 777 $NVM_DIR
54+
chmod -R a+rx $NVM_DIR
55+
56+
cat <<EOT > $NVM_DIR/settings.txt
57+
root: $NVM_HOME
58+
path: $NVM_SYMLINK
59+
EOT
60+
61+
nvm install $NODE_VERSION
62+
nvm use $NODE_VERSION
63+
else
64+
curl -o- $NVM_URL | bash
65+
[ -s "${NVM_DIR}/nvm.sh" ] && \. "${NVM_DIR}/nvm.sh"
66+
nvm install --lts=${NODE_LTS_NAME}
67+
fi
3668

3769
# setup npm cache in a local directory
3870
cat <<EOT > .npmrc

bindings/node/binding.gyp

Lines changed: 67 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,70 @@
11
{
2-
'targets': [
3-
{
4-
'target_name': 'mongocrypt',
5-
'include_dirs': [
6-
'<!(node -e "require(\'nan\')")'
2+
'targets': [{
3+
'target_name': 'mongocrypt',
4+
'include_dirs': [
5+
'<!(node -e "require(\'nan\')")'
6+
],
7+
'variables': {
8+
'variables': {
9+
'build_type%': "dynamic",
10+
},
11+
'conditions': [
12+
['OS=="win"', {
13+
'build_type' : "<!(echo %BUILD_TYPE%)"
14+
}],
15+
['OS!="win"', {
16+
'build_type' : "<!(echo $BUILD_TYPE)",
17+
}]
18+
]
19+
},
20+
'sources': [
21+
'src/mongocrypt.cc'
22+
],
23+
'xcode_settings': {
24+
'MACOSX_DEPLOYMENT_TARGET': '10.12',
25+
'OTHER_CFLAGS': [
26+
"-std=c++11",
27+
"-stdlib=libc++"
728
],
8-
'variables': {
9-
'variables': {
10-
'build_type%': "dynamic",
11-
},
12-
'conditions': [
13-
['OS=="win"', {
14-
'build_type' : "<!(echo %BUILD_TYPE%)"
15-
}],
16-
['OS!="win"', {
17-
'build_type' : "<!(echo $BUILD_TYPE)",
18-
}]
29+
},
30+
'conditions': [
31+
['build_type=="dynamic"', {
32+
'link_settings': {
33+
'libraries': [
34+
'-lmongocrypt'
1935
]
20-
},
21-
'sources': [
22-
'src/mongocrypt.cc'
23-
],
24-
'xcode_settings': {
25-
'MACOSX_DEPLOYMENT_TARGET': '10.12',
26-
'OTHER_CFLAGS': [
27-
"-std=c++11",
28-
"-stdlib=libc++"
29-
],
30-
},
31-
'conditions': [
32-
['build_type=="dynamic"', {
33-
'link_settings': {
34-
'libraries': [
35-
'-lmongocrypt'
36-
]
37-
}
38-
}],
39-
['build_type!="dynamic"', {
40-
'include_dirs': [
41-
'<(module_root_dir)/deps/include'
42-
],
43-
'link_settings': {
44-
'libraries': [
45-
'<(module_root_dir)/deps/lib/libmongocrypt-static.a',
46-
'<(module_root_dir)/deps/lib/libkms_message-static.a',
47-
'<(module_root_dir)/deps/lib/libbson-static-1.0.a'
48-
]
49-
}
50-
}],
51-
],
52-
}
53-
]
54-
}
36+
}
37+
}],
38+
['build_type!="dynamic"', {
39+
'conditions': [
40+
['OS!="win"', {
41+
'include_dirs': [
42+
'<(module_root_dir)/deps/include'
43+
],
44+
'link_settings': {
45+
'libraries': [
46+
'<(module_root_dir)/deps/lib/libmongocrypt-static.a',
47+
'<(module_root_dir)/deps/lib/libkms_message-static.a',
48+
'<(module_root_dir)/deps/lib/libbson-static-1.0.a'
49+
]
50+
}
51+
}],
52+
['OS=="win"', {
53+
'defines': [ 'MONGOCRYPT_STATIC_DEFINE' ],
54+
'include_dirs': [
55+
'<(module_root_dir)/deps/include'
56+
],
57+
'link_settings': {
58+
'libraries': [
59+
'<(module_root_dir)/deps/lib/mongocrypt-static.lib',
60+
'<(module_root_dir)/deps/lib/kms_message-static.lib',
61+
'<(module_root_dir)/deps/lib/bson-static-1.0.lib',
62+
'-lws2_32'
63+
]
64+
}
65+
}]
66+
]
67+
}]
68+
]
69+
}]
70+
}

bindings/node/etc/build-static.sh

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,30 @@ pushd $BUILD_DIR #./deps/tmp
2323
pushd $TOP_DIR
2424
# build and install bson
2525

26-
# NOTE: we are setting -DCMAKE_INSTALL_LIBDIR=lib to ensure that the built
26+
# NOTE: we are setting -DCMAKE_INSTALL_LIBDIR=lib to ensure that the built
2727
# files are always installed to lib instead of alternate directories like
2828
# lib64.
2929
# NOTE: On OSX, -DCMAKE_OSX_DEPLOYMENT_TARGET can be set to an OSX version
3030
# to suppress build warnings. However, doing that tends to break some
3131
# of the versions that can be built
32-
export BSON_EXTRA_CMAKE_FLAGS="-DCMAKE_INSTALL_LIBDIR=lib -DCMAKE_OSX_DEPLOYMENT_TARGET=\"10.12\""
33-
32+
export BSON_EXTRA_CMAKE_FLAGS="-DCMAKE_INSTALL_LIBDIR=lib -DCMAKE_OSX_DEPLOYMENT_TARGET=\"10.12\" -DCMAKE_C_FLAGS_RELWITHDEBINFO=\"/MT\""
3433
. ${TOP_DIR}/libmongocrypt/.evergreen/build_install_bson.sh
3534

3635
popd #./deps/tmp
3736

3837
# build and install libmongocrypt
3938
pushd libmongocrypt-build #./deps/tmp/libmongocrypt-build
40-
$CMAKE -DDISABLE_NATIVE_CRYPTO=1 -DCMAKE_C_FLAGS="-fPIC" -DCMAKE_PREFIX_PATH=$DEPS_PREFIX -DCMAKE_INSTALL_PREFIX=$DEPS_PREFIX -DCMAKE_INSTALL_LIBDIR=lib -DCMAKE_OSX_DEPLOYMENT_TARGET="10.12" $LIBMONGOCRYPT_DIR
41-
make -j8 install
39+
40+
CMAKE_FLAGS="-DDISABLE_NATIVE_CRYPTO=1 -DCMAKE_C_FLAGS=\"-fPIC\" -DCMAKE_INSTALL_LIBDIR=lib "
41+
if [ "$OS" == "Windows_NT" ]; then
42+
WINDOWS_CMAKE_FLAGS="-Thost=x64 -A x64 -DCMAKE_C_FLAGS_RELWITHDEBINFO=\"/MT\""
43+
$CMAKE $CMAKE_FLAGS $WINDOWS_CMAKE_FLAGS -DCMAKE_PREFIX_PATH=$DEPS_PREFIX -DCMAKE_INSTALL_PREFIX=$DEPS_PREFIX "`cygpath -w $LIBMONGOCRYPT_DIR`"
44+
else
45+
$CMAKE $CMAKE_FLAGS -DCMAKE_PREFIX_PATH=$DEPS_PREFIX -DCMAKE_INSTALL_PREFIX=$DEPS_PREFIX -DCMAKE_OSX_DEPLOYMENT_TARGET="10.12" $LIBMONGOCRYPT_DIR
46+
fi
47+
48+
$CMAKE --build . --target install --config RelWithDebInfo
49+
4250
popd #./deps/tmp
4351

4452
popd #./deps

0 commit comments

Comments
 (0)