Skip to content

Commit

Permalink
fix: build jpegturbo as shared lib on linux
Browse files Browse the repository at this point in the history
  • Loading branch information
Julusian committed Oct 28, 2023
1 parent 1ff87a9 commit 796f4c0
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 12 deletions.
22 changes: 19 additions & 3 deletions .github/workflows/node.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,28 @@ jobs:
- os: ubuntu-18.04
arch: x64
is-native: true
extra-copy-args: --extraFiles libturbojpeg.so.0
# linux-libc
- os: ubuntu-latest
arch: arm64
is-native: false
docker-arch: linux/arm64
docker-image: node:16-buster
extra-copy-args: --extraFiles libturbojpeg.so.0
- os: ubuntu-latest
arch: arm
is-native: false
docker-arch: linux/arm/v7
docker-image: node:16-buster
extra-copy-args: --extraFiles libturbojpeg.so.0
# linux-musl
- os: ubuntu-latest
arch: x64
is-native: false
docker-arch: linux/amd64
docker-image: node:16-alpine
libc: musl
extra-copy-args: --extraFiles libturbojpeg.so.0

steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -98,7 +102,13 @@ jobs:
fi
yarn rebuild --arch=${{ matrix.arch }}
yarn pkg-prebuilds-copy --source build/Release/$BINDING_NAME.node --name=$BINDING_NAME --strip --napi_version=$NAPI_VERSION --arch=${{ matrix.arch }}
yarn pkg-prebuilds-copy ${{ matrix.extra-copy-args }} \
--baseDir build/Release \
--source $BINDING_NAME.node \
--name=$BINDING_NAME \
--strip \
--napi_version=$NAPI_VERSION \
--arch=${{ matrix.arch }}
env:
CI: true
npm_config_build_from_source: true
Expand Down Expand Up @@ -129,8 +139,14 @@ jobs:
yarn
yarn test
yarn pkg-prebuilds-copy --source build/Release/$BINDING_NAME.node --name=$BINDING_NAME --strip --napi_version=$NAPI_VERSION --arch=${{ matrix.arch }} --libc=${{ matrix.libc }}
yarn pkg-prebuilds-copy ${{ matrix.extra-copy-args }} \
--baseDir build/Release \
--source $BINDING_NAME.node \
--name=$BINDING_NAME \
--strip \
--napi_version=$NAPI_VERSION \
--arch=${{ matrix.arch }} \
--libc=${{ matrix.libc }}
- name: Upload artifacts
uses: actions/upload-artifact@v3
Expand Down
20 changes: 17 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,28 @@ set(SOURCE_FILES
"src/exports.cc"
)

option(WITH_JPEG8 "" 1)
option(ENABLE_SHARED "" 0)
if(UNIX AND NOT APPLE)
# build shared on linux, to avoid conflicts with libjpeg built into electron
option(ENABLE_SHARED "" 1)
option(ENABLE_STATIC "" 0)
set(LINK_JPEG "turbojpeg")
else()
# build static elsewhere
option(ENABLE_SHARED "" 0)
option(ENABLE_STATIC "" 1)
set(LINK_JPEG "turbojpeg-static")
endif()

option(WITH_JPEG8 "" 0)
add_subdirectory("deps/libjpeg-turbo")

set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
set(CMAKE_INSTALL_RPATH "$ORIGIN")

add_library(${PROJECT_NAME} SHARED ${SOURCE_FILES} ${HEADER_FILES} ${CMAKE_JS_SRC})
set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "" SUFFIX ".node")
target_include_directories(${PROJECT_NAME} PRIVATE "deps/libjpeg-turbo")
target_link_libraries(${PROJECT_NAME} ${CMAKE_JS_LIB} turbojpeg-static)
target_link_libraries(${PROJECT_NAME} ${CMAKE_JS_LIB} ${LINK_JPEG})

if(MSVC AND CMAKE_JS_NODELIB_DEF AND CMAKE_JS_NODELIB_TARGET)
# Generate node.lib
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@julusian/jpeg-turbo",
"version": "2.1.0",
"version": "2.2.0-0",
"description": "Limited libjpeg-turbo bindings for Node.js.",
"keywords": [
"jpeg",
Expand All @@ -25,10 +25,11 @@
"dependencies": {
"cmake-js": "^7.2.0",
"node-addon-api": "^6.0.0",
"pkg-prebuilds": "~0.1.0"
"pkg-prebuilds": "~0.2.0"
},
"scripts": {
"install": "pkg-prebuilds-verify ./binding-options.js || cmake-js compile --target jpeg-turbo",
"build": "cmake-js build --target jpeg-turbo",
"rebuild": "cmake-js rebuild --target jpeg-turbo",
"test": "jest"
},
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2037,10 +2037,10 @@ pkg-dir@^4.2.0:
dependencies:
find-up "^4.0.0"

pkg-prebuilds@~0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/pkg-prebuilds/-/pkg-prebuilds-0.1.0.tgz#7ac38674146708e763a4581a0759d5e8594f61b6"
integrity sha512-ALsGSiwO6EDvjrrFRiv7Q6HZPrqCgTpNxQMFs3P4Ic25cP94DmLy0iGvZDlJmQBbq2IS8xkZrifwkoOHIetY9Q==
pkg-prebuilds@~0.2.0:
version "0.2.1"
resolved "https://registry.yarnpkg.com/pkg-prebuilds/-/pkg-prebuilds-0.2.1.tgz#4b91f410ab600df4eb657634d623549cc188c5ed"
integrity sha512-FdOlDiRqRL7i9aYzQflhGWCoiJf/8u6Qgzq48gKsRDYejtfjvGb1U5QGSzllcqpNg2a8Swx/9fMgtuVefwU+zw==
dependencies:
yargs "^17.5.1"

Expand Down

0 comments on commit 796f4c0

Please sign in to comment.