Skip to content

Commit

Permalink
feat: ci
Browse files Browse the repository at this point in the history
  • Loading branch information
hpp2334 committed Jun 14, 2024
1 parent ecfbf7a commit 42867c3
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 4 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Build and test
on: [push]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v4
with:
node-version: 20
- uses: pnpm/action-setup@v2
with:
version: 8
- name: Prepare emscripten
run: node ./scripts/install-emscripten.mjs
- name: Prepare dependencies
run: |
pnpm install
- name: Run build wasm
shell: bash
run: |
source ./emsdk/emsdk_env.sh
pnpm run build:js
env:
EMSCRIPTEN_ROOT: ${{ github.workspace }}/emsdk
CC: clang
CXX: clang++
- name: Run test wasm (Wasm)
run: |
pnpx playwright install-deps
pnpx playwright install
pnpm run test:js
env:
TEST_WEBKIT: 1
- name: Run build & tests (C++)
run: |
pnpm run build:native
pnpm run test:native
env:
CC: clang
CXX: clang++
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# elheif

A wasm heic image encoder and decoder library compiled from [libheif](https://github.com/strukturag/libheif), [libde265](https://github.com/strukturag/libde265) and kvazaar. The library is just a wrapper of `libheif` and compiled to WASM using Emscripten
![Main](https://github.com/hpp2334/elheif/actions/workflows/main.yml/badge.svg)
[![npm version](https://badge.fury.io/js/elheif.svg)](https://badge.fury.io/js/elheif)

A wasm heic image encoder and decoder library compiled from [libheif](https://github.com/strukturag/libheif), [libde265](https://github.com/strukturag/libde265) and kvazaar. The library is just a wrapper of `libheif` and compiled to WASM using Emscripten.

## API

Expand Down
3 changes: 2 additions & 1 deletion core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ include(ExternalProject)

option(EMSCRIPTEN "Build to empscripten")


set(EXTRA_CXX_FLAGS "-D__EMSCRIPTEN_STANDALONE_WASM__=1")
# set(EXTRA_CXX_FLAGS "-D__EMSCRIPTEN_STANDALONE_WASM__=1 -pthread")

Expand Down Expand Up @@ -50,7 +51,7 @@ ExternalProject_Add(
SOURCE_DIR ${CMAKE_BINARY_DIR}/libheif-src
BINARY_DIR ${CMAKE_BINARY_DIR}/libheif-build
TEST_COMMAND ""
CMAKE_ARGS -DWITH_KVAZAAR=ON -DWITH_EXAMPLES=OFF -DENABLE_MULTITHREADING_SUPPORT=OFF -DBUILD_TESTING=OFF -DBUILD_SHARED_LIBS=OFF -DLIBDE265_INCLUDE_DIR=${LIBDE265_INCLUDE_DIR} -DLIBDE265_LIBRARY=${LIBDE265_LIBRARY} -DKVAZAAR_INCLUDE_DIR=${KVAZAAR_INCLUDE_DIR} -DKVAZAAR_LIBRARY=${KVAZAAR_LIBRARY} ${EXTERNAL_PROJECT_EXTRA_CMAKE_ARGS}
CMAKE_ARGS -DWITH_KVAZAAR=ON -DWITH_GDK_PIXBUF=OFF -DWITH_EXAMPLES=OFF -DENABLE_MULTITHREADING_SUPPORT=OFF -DBUILD_TESTING=OFF -DBUILD_SHARED_LIBS=OFF -DLIBDE265_INCLUDE_DIR=${LIBDE265_INCLUDE_DIR} -DLIBDE265_LIBRARY=${LIBDE265_LIBRARY} -DKVAZAAR_INCLUDE_DIR=${KVAZAAR_INCLUDE_DIR} -DKVAZAAR_LIBRARY=${KVAZAAR_LIBRARY} ${EXTERNAL_PROJECT_EXTRA_CMAKE_ARGS}
)

set(CMAKE_CXX_STANDARD 17)
Expand Down
20 changes: 20 additions & 0 deletions scripts/install-emscripten.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { execSync } from "child_process";
import * as path from 'path'

const EMSDK_VERSION = '3.1.60'

const ROOT = path.resolve(import.meta.dirname, '../')
const EMSDK_ROOT = path.resolve(ROOT, './emsdk')

execSync('git clone https://github.com/emscripten-core/emsdk.git', {
stdio: 'inherit',
cwd: ROOT,
})
execSync(`./emsdk install ${EMSDK_VERSION}`, {
stdio: 'inherit',
cwd: EMSDK_ROOT,
})
execSync(`./emsdk activate ${EMSDK_VERSION}`, {
stdio: 'inherit',
cwd: EMSDK_ROOT,
})
7 changes: 6 additions & 1 deletion tests/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,10 @@ TEST(HeifTest, Encode) {

// Expect equality.
EXPECT_EQ(encoded.err, "");
EXPECT_EQ(encoded.data.size(), 110151);

auto decoded2 = Elheif::decode(encoded.data.data(), encoded.data.size());
EXPECT_EQ(decoded2.data.size(), 1);
EXPECT_EQ(decoded2.err, "");
EXPECT_EQ(decoded2.data[0].width, 1280);
EXPECT_EQ(decoded2.data[0].height, 720);
}
3 changes: 2 additions & 1 deletion web-test-runner.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ export default {
playwrightLauncher({
product: 'chromium',
}),
playwrightLauncher({ product: 'firefox' }),
...(process.env.TEST_WEBKIT ? [playwrightLauncher({ product: 'webkit' })] : []),
],
plugins: [
esbuildPlugin({ ts: true }),
],
middleware: [add_headers],
coverage: true,
coverageConfig: {
reporters: ['lcovonly', 'clover'],
Expand Down

0 comments on commit 42867c3

Please sign in to comment.