|
1 | 1 | #!/bin/sh
|
2 | 2 | set -o xtrace
|
3 |
| -set -o errexit |
4 | 3 |
|
5 | 4 | clean_deps() {
|
6 | 5 | rm -rf deps
|
7 | 6 | }
|
8 | 7 |
|
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 |
| - |
20 | 8 | download_zstd() {
|
21 | 9 | mkdir -p deps/zstd
|
22 | 10 | 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 |
| 11 | + |
| 12 | + # only unpack the source and build files needed to compile the project |
| 13 | + necessary_files="zstd-$ZSTD_VERSION/build zstd-$ZSTD_VERSION/lib zstd-$ZSTD_VERSION/programs" |
| 14 | + |
| 15 | + # flags |
| 16 | + # -L follow redirects |
| 17 | + # -C output directory |
| 18 | + # - tar from stdin |
| 19 | + # --strip-components ignore the top-level directory when unpacking |
| 20 | + curl -L "https://github.com/facebook/zstd/releases/download/v$ZSTD_VERSION/zstd-$ZSTD_VERSION.tar.gz" \ |
| 21 | + | tar -zxf - -C deps/zstd --strip-components 1 $necessary_files |
37 | 22 | }
|
38 | 23 |
|
39 | 24 | build_zstd() {
|
40 | 25 | export MACOSX_DEPLOYMENT_TARGET=11
|
41 |
| - cd deps/zstd/build/cmake |
| 26 | + cd deps/zstd |
| 27 | + |
| 28 | + mkdir out |
| 29 | + cd out |
42 | 30 |
|
43 | 31 | # CMAKE_RC_FLAGS is a workaround for a bug in 1.5.6 that breaks compilation on windows.
|
44 | 32 | # 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 . |
| 33 | + cmake \ |
| 34 | + -DCMAKE_RC_FLAGS="$(pwd)/lib" \ |
| 35 | + -DZSTD_MULTITHREAD_SUPPORT=OFF \ |
| 36 | + -DZSTD_BUILD_SHARED=OFF \ |
| 37 | + -DCMAKE_OSX_ARCHITECTURES='x86_64;arm64' \ |
| 38 | + -DCMAKE_BUILD_TYPE=Release \ |
| 39 | + ../build/cmake |
| 40 | + |
| 41 | + cmake --build . --target libzstd_static |
47 | 42 | }
|
48 | 43 |
|
49 | 44 | clean_deps
|
|
0 commit comments