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

build(NODE-6604): fix windows builds #52

Merged
merged 2 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
shell: bash

- name: install dependencies and compile
run: npm install --loglevel verbose
run: npm install --ignore-scripts --loglevel verbose && npm run prebuild
nbbeeken marked this conversation as resolved.
Show resolved Hide resolved
shell: bash

- name: Test ${{ matrix.os }}
Expand Down
7 changes: 2 additions & 5 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,14 @@
{
'link_settings': {
'libraries': [
'<(module_root_dir)/deps/zstd/static/zstd_static.lib'
'<(module_root_dir)/deps/zstd/out/lib/Debug/zstd_static.lib'
]
},
'include_dirs': [
'<(module_root_dir)/deps/zstd/include'
],
},
{ # macos and linux
'link_settings': {
'libraries': [
'<(module_root_dir)/deps/zstd/build/cmake/lib/libzstd.a',
'<(module_root_dir)/deps/zstd/out/lib/libzstd.a',
]
},
}
Expand Down
52 changes: 24 additions & 28 deletions etc/install-zstd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,40 @@ clean_deps() {
rm -rf deps
}

download_windows() {
# windows does not support symlinks, so we must download the `win64` build specifically
curl -L -o zstd.zip "https://github.com/facebook/zstd/releases/download/v$ZSTD_VERSION/zstd-v$ZSTD_VERSION-win64.zip"
# unlike tar, unzip does not have a "strip components" option. so we unzip the file, copy all the contents to the correct location,
# and then delete both the .zip and the unziped content.
unzip zstd.zip
cp -r zstd-v$ZSTD_VERSION-win64/* deps/zstd
rm zstd.zip
rm -rf zstd-v$ZSTD_VERSION-win64
}

download_zstd() {
mkdir -p deps/zstd
ZSTD_VERSION=$(node -p "require('./package.json')['mongodb:zstd_version']")
is_windows=$(node -p "process.platform === 'win32'")

if [ "$is_windows" == "true" ]; then
download_windows
exit 0 # no need to build windows
else
# tar flags
# -C specifies the output location
# --strip-components removes one level of directory nesting
# curl flags
# -L follows redirects
curl -L "https://github.com/facebook/zstd/releases/download/v$ZSTD_VERSION/zstd-$ZSTD_VERSION.tar.gz" \
| tar -zxf - -C deps/zstd --strip-components 1
fi

# only unpack the source and build files needed to compile the project
necessary_files="zstd-$ZSTD_VERSION/build zstd-$ZSTD_VERSION/lib zstd-$ZSTD_VERSION/programs"

# flags
# -L follow redirects
# -C output directory
# - tar from stdin
# --strip-components ignore the top-level directory when unpacking
curl -L "https://github.com/facebook/zstd/releases/download/v$ZSTD_VERSION/zstd-$ZSTD_VERSION.tar.gz" \
| tar -zxf - -C deps/zstd --strip-components 1 $necessary_files
}

build_zstd() {
export MACOSX_DEPLOYMENT_TARGET=11
cd deps/zstd/build/cmake
cd deps/zstd

mkdir out
cd out

# CMAKE_RC_FLAGS is a workaround for a bug in 1.5.6 that breaks compilation on windows.
# The fix is merged but not yet released. see https://github.com/facebook/zstd/issues/3999
cmake -DCMAKE_RC_FLAGS="$(pwd)/lib" -DZSTD_MULTITHREAD_SUPPORT=OFF -DZSTD_BUILD_SHARED=OFF -DCMAKE_OSX_ARCHITECTURES='x86_64;arm64' .
cmake --build .
cmake \
-DCMAKE_RC_FLAGS="$(pwd)/lib" \
-DZSTD_MULTITHREAD_SUPPORT=OFF \
-DZSTD_BUILD_SHARED=OFF \
-DCMAKE_OSX_ARCHITECTURES='x86_64;arm64' \
-DCMAKE_BUILD_TYPE=Release \
../build/cmake

cmake --build . --target libzstd_static
nbbeeken marked this conversation as resolved.
Show resolved Hide resolved
}

clean_deps
Expand Down
Loading