Skip to content

Commit 57b9640

Browse files
authoredDec 5, 2024··
build(NODE-6604): fix windows builds (#52)
1 parent 7d8c6de commit 57b9640

File tree

3 files changed

+27
-34
lines changed

3 files changed

+27
-34
lines changed
 

‎.github/workflows/test.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
shell: bash
3030

3131
- name: install dependencies and compile
32-
run: npm install --loglevel verbose
32+
run: npm install --ignore-scripts --loglevel verbose && npm run prebuild
3333
shell: bash
3434

3535
- name: Test ${{ matrix.os }}

‎binding.gyp

+2-5
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,14 @@
2323
{
2424
'link_settings': {
2525
'libraries': [
26-
'<(module_root_dir)/deps/zstd/static/zstd_static.lib'
26+
'<(module_root_dir)/deps/zstd/out/lib/Debug/zstd_static.lib'
2727
]
2828
},
29-
'include_dirs': [
30-
'<(module_root_dir)/deps/zstd/include'
31-
],
3229
},
3330
{ # macos and linux
3431
'link_settings': {
3532
'libraries': [
36-
'<(module_root_dir)/deps/zstd/build/cmake/lib/libzstd.a',
33+
'<(module_root_dir)/deps/zstd/out/lib/libzstd.a',
3734
]
3835
},
3936
}

‎etc/install-zstd.sh

+24-28
Original file line numberDiff line numberDiff line change
@@ -6,44 +6,40 @@ clean_deps() {
66
rm -rf deps
77
}
88

9-
download_windows() {
10-
# windows does not support symlinks, so we must download the `win64` build specifically
11-
curl -L -o zstd.zip "https://github.com/facebook/zstd/releases/download/v$ZSTD_VERSION/zstd-v$ZSTD_VERSION-win64.zip"
12-
# unlike tar, unzip does not have a "strip components" option. so we unzip the file, copy all the contents to the correct location,
13-
# and then delete both the .zip and the unziped content.
14-
unzip zstd.zip
15-
cp -r zstd-v$ZSTD_VERSION-win64/* deps/zstd
16-
rm zstd.zip
17-
rm -rf zstd-v$ZSTD_VERSION-win64
18-
}
19-
209
download_zstd() {
2110
mkdir -p deps/zstd
2211
ZSTD_VERSION=$(node -p "require('./package.json')['mongodb:zstd_version']")
23-
is_windows=$(node -p "process.platform === 'win32'")
24-
25-
if [ "$is_windows" == "true" ]; then
26-
download_windows
27-
exit 0 # no need to build windows
28-
else
29-
# tar flags
30-
# -C specifies the output location
31-
# --strip-components removes one level of directory nesting
32-
# curl flags
33-
# -L follows redirects
34-
curl -L "https://github.com/facebook/zstd/releases/download/v$ZSTD_VERSION/zstd-$ZSTD_VERSION.tar.gz" \
35-
| tar -zxf - -C deps/zstd --strip-components 1
36-
fi
12+
13+
# only unpack the source and build files needed to compile the project
14+
necessary_files="zstd-$ZSTD_VERSION/build zstd-$ZSTD_VERSION/lib zstd-$ZSTD_VERSION/programs"
15+
16+
# flags
17+
# -L follow redirects
18+
# -C output directory
19+
# - tar from stdin
20+
# --strip-components ignore the top-level directory when unpacking
21+
curl -L "https://github.com/facebook/zstd/releases/download/v$ZSTD_VERSION/zstd-$ZSTD_VERSION.tar.gz" \
22+
| tar -zxf - -C deps/zstd --strip-components 1 $necessary_files
3723
}
3824

3925
build_zstd() {
4026
export MACOSX_DEPLOYMENT_TARGET=11
41-
cd deps/zstd/build/cmake
27+
cd deps/zstd
28+
29+
mkdir out
30+
cd out
4231

4332
# CMAKE_RC_FLAGS is a workaround for a bug in 1.5.6 that breaks compilation on windows.
4433
# The fix is merged but not yet released. see https://github.com/facebook/zstd/issues/3999
45-
cmake -DCMAKE_RC_FLAGS="$(pwd)/lib" -DZSTD_MULTITHREAD_SUPPORT=OFF -DZSTD_BUILD_SHARED=OFF -DCMAKE_OSX_ARCHITECTURES='x86_64;arm64' .
46-
cmake --build .
34+
cmake \
35+
-DCMAKE_RC_FLAGS="$(pwd)/lib" \
36+
-DZSTD_MULTITHREAD_SUPPORT=OFF \
37+
-DZSTD_BUILD_SHARED=OFF \
38+
-DCMAKE_OSX_ARCHITECTURES='x86_64;arm64' \
39+
-DCMAKE_BUILD_TYPE=Release \
40+
../build/cmake
41+
42+
cmake --build . --target libzstd_static
4743
}
4844

4945
clean_deps

0 commit comments

Comments
 (0)
Please sign in to comment.