Skip to content
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
22 changes: 22 additions & 0 deletions .github/docker/Dockerfile.glibc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
ARG UBUNTU_VERSION=bionic
FROM ubuntu:${UBUNTU_VERSION} AS build

ARG NODE_VERSION=16.20.1
# Possible values: s390x, arm64, x64
ARG NODE_ARCH
ADD https://nodejs.org/dist/v${NODE_VERSION}/node-v${NODE_VERSION}-linux-${NODE_ARCH}.tar.gz /
RUN mkdir -p /nodejs && tar -xzf /node-v${NODE_VERSION}-linux-${NODE_ARCH}.tar.gz --strip-components=1 -C /nodejs
ENV PATH=$PATH:/nodejs/bin

WORKDIR /zstd
COPY . .

RUN apt-get -qq update
RUN apt-get -qq install -y python3 build-essential curl cmake
RUN python3 --version

RUN npm run install-zstd
RUN npm install

ARG RUN_TEST
RUN if [ -n "$RUN_TEST" ]; then npm test ; else echo "skipping tests" ; fi
14 changes: 14 additions & 0 deletions .github/docker/Dockerfile.musl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

ARG PLATFORM=arm64
ARG NODE_VERSION=16.20.1

FROM ${PLATFORM}/node:${NODE_VERSION}-alpine AS node

WORKDIR /zstd
COPY . .

RUN apk --no-cache add make g++ libc-dev curl bash python3 py3-pip vim cmake
RUN npm run install-zstd && npm i

ARG RUN_TEST
RUN if [ -n "$RUN_TEST" ]; then npm test ; else echo "skipping tests" ; fi
125 changes: 82 additions & 43 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ jobs:
host_tests:
strategy:
matrix:
# os: [macos-latest, windows-2019]
os: ['ubuntu-latest']
node: [16.20.1, 18.x, 20.x, 22.x]
os: [macos-latest, windows-2019]
node: [16.20.1, 18.x, 20.x, 22.x]
fail-fast: false
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
cache: 'npm'
registry-url: 'https://registry.npmjs.org'
cache: "npm"
registry-url: "https://registry.npmjs.org"

- name: Install zstd
run: npm run install-zstd
Expand All @@ -36,41 +36,80 @@ jobs:
shell: bash
run: npm test

# container_tests:
# runs-on: ubuntu-latest
# strategy:
# matrix:
# linux_arch: [s390x, arm64, amd64]
# node: [16.x, 18.x, 20.x, 22.x]
# steps:
# - uses: actions/checkout@v4

# - uses: actions/setup-node@v4
# with:
# node-version: ${{ matrix.node }}

# - name: Get Full Node.js Version
# id: get_nodejs_version
# shell: bash
# run: |
# echo "version=$(node --print 'process.version.slice(1)')" >> "$GITHUB_OUTPUT"
# echo "ubuntu_version=$(node --print '(+process.version.slice(1).split(`.`).at(0)) > 16 ? `noble` : `bionic`')" >> "$GITHUB_OUTPUT"

# - name: Set up QEMU
# uses: docker/setup-qemu-action@v3

# - name: Set up Docker Buildx
# uses: docker/setup-buildx-action@v3

# - name: Run Buildx
# run: |
# docker buildx create --name builder --bootstrap --use
# docker buildx build \
# --platform linux/${{ matrix.linux_arch }} \
# --build-arg="NODE_ARCH=${{ matrix.linux_arch == 'amd64' && 'x64' || matrix.linux_arch }}" \
# --build-arg="NODE_VERSION=${{ steps.get_nodejs_version.outputs.version }}" \
# --build-arg="UBUNTU_VERSION=${{ steps.get_nodejs_version.outputs.ubuntu_version }}" \
# --build-arg="RUN_TEST=true" \
# --output type=local,dest=./prebuilds,platform-split=false \
# -f ./.github/docker/Dockerfile.glibc \
# .
container_tests_glibc:
runs-on: ubuntu-latest
strategy:
matrix:
linux_arch: [s390x, arm64, amd64]
node: [16.x, 18.x, 20.x, 22.x]
fail-fast: false
steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}

- name: Get Full Node.js Version
id: get_nodejs_version
shell: bash
run: |
echo "version=$(node --print 'process.version.slice(1)')" >> "$GITHUB_OUTPUT"
echo "ubuntu_version=$(node --print '(+process.version.slice(1).split(`.`).at(0)) > 16 ? `noble` : `bionic`')" >> "$GITHUB_OUTPUT"

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Run Buildx
run: |
docker buildx create --name builder --bootstrap --use
docker buildx build \
--platform linux/${{ matrix.linux_arch }} \
--build-arg="NODE_ARCH=${{ matrix.linux_arch == 'amd64' && 'x64' || matrix.linux_arch }}" \
--build-arg="NODE_VERSION=${{ steps.get_nodejs_version.outputs.version }}" \
--build-arg="UBUNTU_VERSION=${{ steps.get_nodejs_version.outputs.ubuntu_version }}" \
--build-arg="RUN_TEST=true" \
--output type=local,dest=./prebuilds,platform-split=false \
-f ./.github/docker/Dockerfile.glibc \
.

container_tests_musl:
runs-on: ubuntu-latest
strategy:
matrix:
linux_arch: [amd64, arm64]
node: [16.20.1, 18.x, 20.x, 22.x]
fail-fast: false
steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}

- name: Get Full Node.js Version
id: get_nodejs_version
shell: bash
run: |
echo "version=$(node --print 'process.version.slice(1)')" >> "$GITHUB_OUTPUT"

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Run Buildx
run: |
docker buildx create --name builder --bootstrap --use
docker --debug buildx build --progress=plain --no-cache \
--platform linux/${{ matrix.linux_arch }} \
--build-arg="PLATFORM=${{ matrix.linux_arch == 'arm64' && 'arm64v8' || matrix.linux_arch }}" \
--build-arg="NODE_VERSION=${{ steps.get_nodejs_version.outputs.version }}" \
--build-arg="RUN_TEST=true" \
--output type=local,dest=./prebuilds,platform-split=false \
-f ./.github/docker/Dockerfile.musl \
.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ build

npm-debug.log
deps

prebuilds
3 changes: 2 additions & 1 deletion .mocharc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"extension": ["ts"],
"recursive": true,
"failZero": true,
"color": true
"color": true,
"timeout": 0
}
2 changes: 1 addition & 1 deletion addon/compression.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef MONGODB_ZSTD_COMPRESSION
#define MONGODB_ZSTD_COMPRESSION

#include <exception>
#include <stdexcept>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was actually the wrong include.

#include <vector>

#include "compression_worker.h"
Expand Down
41 changes: 32 additions & 9 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,45 @@
'addon/compression.h',
'addon/compression.cpp'
],
'conditions': [
[
'OS=="win"',
{
'link_settings': {
'libraries': [
'<(module_root_dir)/deps/zstd/build/cmake/lib/Debug/zstd_static.lib'
]
},
},
{ # macos and linux
'link_settings': {
'libraries': [
'<(module_root_dir)/deps/zstd/build/cmake/lib/libzstd.a',
]
},
}
]
],
'cflags!': [ '-fno-exceptions' ],
'cflags_cc!': [ '-fno-exceptions' ],
'cflags_cc': ['-std=c++17'],
'xcode_settings': {
'GCC_ENABLE_CPP_EXCEPTIONS': 'YES',
'CLANG_CXX_LIBRARY': 'libc++',
'MACOSX_DEPLOYMENT_TARGET': '11',
'GCC_SYMBOLS_PRIVATE_EXTERN': 'YES', # -fvisibility=hidden
'OTHER_CFLAGS': [
'-std=c++17',
'-stdlib=libc++'
],
},
'cflags!': [ '-fno-exceptions' ],
'cflags_cc!': [ '-fno-exceptions' ],
'cflags_cc': ['-std=c++17'],
'msvs_settings': {
'VCCLCompilerTool': { 'ExceptionHandling': 1 },
},
'link_settings': {
'libraries': [
'<(module_root_dir)/deps/zstd/build/cmake/lib/libzstd.a',
]
'VCCLCompilerTool': {
'ExceptionHandling': 1,
'AdditionalOptions': [
'-std:c++17'
]
}
},
}]
}
46 changes: 46 additions & 0 deletions etc/docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#! /bin/bash

# script to aid in local testing of linux platforms
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy to remove, but this is a handy script to run our tests locally in linux containers.

# requires a running docker instance

# s390x, arm64, amd64 for ubuntu
# amd64 or arm64v8 for alpine
LINUX_ARCH=arm64

# 16.20.1+, default 16.20.1
NODE_VERSION=18.0.0

SCRIPT_DIR=$(dirname ${BASH_SOURCE:-$0})
PROJECT_DIR=$SCRIPT_DIR/..

build_and_test_musl() {
docker buildx create --name builder --bootstrap --use

docker --debug buildx build --load --progress=plain --no-cache \
--platform linux/$LINUX_ARCH --output=type=docker \
--build-arg="PLATFORM=$LINUX_ARCH" \
--build-arg="NODE_VERSION=$NODE_VERSION" \
--build-arg="RUN_TEST=true" \
-f ./.github/docker/Dockerfile.musl -t musl-zstd-base \
.
}

build_and_test_glibc() {
docker buildx create --name builder --bootstrap --use

UBUNTU_VERSION=ubuntu_version=$(node --print '(process.argv[1].slice(1).split(`.`).at(0)) > 16 ? `noble` : `bionic`' $NODE_VERSION)
NODE_ARCH=$(node -p 'process.argv[1] === `amd64` && `x64` || process.argv[1]' $LINUX_ARCH)
echo $UBUNTU_VERSION
docker buildx build --progress=plain --no-cache \
--platform linux/$LINUX_ARCH \
--build-arg="NODE_ARCH=$NODE_ARCH" \
--build-arg="NODE_VERSION=$NODE_VERSION" \
--build-arg="UBUNTU_VERSION$UBUNTU_VERSION" \
--build-arg="RUN_TEST=true" \
--output type=local,dest=./prebuilds,platform-split=false \
-f ./.github/docker/Dockerfile.glibc \
$PROJECT_DIR
}


build_and_test_musl
6 changes: 4 additions & 2 deletions etc/install-zstd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ build_zstd() {
export MACOSX_DEPLOYMENT_TARGET=11
cd deps/zstd/build/cmake

cmake .
make
# 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 .
cmake --build .
}

clean_deps
Expand Down
Loading