Skip to content

Commit

Permalink
support macos build
Browse files Browse the repository at this point in the history
  • Loading branch information
eagleoflqj committed Aug 15, 2023
1 parent d5a7f7f commit 16bedce
Show file tree
Hide file tree
Showing 9 changed files with 258 additions and 106 deletions.
81 changes: 14 additions & 67 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
name: build

on:
push:
branches:
- master
pull_request:
workflow_call:
inputs:
os:
required: true
type: string

jobs:
build:
runs-on: ubuntu-latest
runs-on: ${{ inputs.os }}
steps:
- uses: actions/checkout@v3
- name: Install RIME dependencies
- name: Install Ubuntu dependencies
if: ${{ inputs.os == 'ubuntu-latest' }}
run: |
sudo apt install -y ninja-build \
clang-format \
Expand All @@ -23,6 +25,10 @@ jobs:
libleveldb-dev \
libmarisa-dev \
libopencc-dev
- name: Install macOS dependencies
if: ${{ inputs.os == 'macos-latest' }}
run: |
brew install ninja clang-format
- name: Use Node.js latest
uses: actions/setup-node@v2
with:
Expand Down Expand Up @@ -60,70 +66,11 @@ jobs:
run: |
pnpm run build
- name: Tar files
if: ${{ inputs.os == 'ubuntu-latest' }}
run: tar --exclude=build/librime_native/bin/build -cvf artifact.tar build/librime_native/bin dist
- name: Upload artifact
if: ${{ inputs.os == 'ubuntu-latest' }}
uses: actions/upload-artifact@v3
with:
name: artifact.tar
path: artifact.tar

test:
needs: build
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
browser: [chromium, firefox] # webkit
include:
- os: macos-latest
browser: webkit

steps:
- uses: actions/checkout@v3
- name: Use Node.js latest
uses: actions/setup-node@v2
with:
node-version: 20.x
- name: Install node dependencies
run: |
npm i -g pnpm
pnpm i
npx playwright install ${{ matrix.browser }}
npx playwright install-deps ${{ matrix.browser }}
- name: Download artifact
uses: actions/download-artifact@v3
with:
name: artifact.tar
- name: Untar files
run: tar -xvf artifact.tar
- name: Test
if: ${{ matrix.os == 'ubuntu-latest' }}
run: |
npx playwright test --browser ${{ matrix.browser }} test/
- name: Test device
if: ${{ matrix.os == 'macos-latest' }}
run: |
npx playwright test --browser ${{ matrix.browser }} test-device/
release:
needs: test
if: ${{ github.ref == 'refs/heads/master' }}
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v3
- name: Download artifact
uses: actions/download-artifact@v3
with:
name: artifact.tar
- name: Untar files
run: tar -xvf artifact.tar
- name: Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
mv dist my-rime-dist
zip -r my-rime-dist.zip my-rime-dist
gh release upload latest my-rime-dist.zip --clobber
79 changes: 79 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: build

on:
push:
branches:
- master
pull_request:

jobs:
build-ubuntu:
uses: ./.github/workflows/build.yml
with:
os: ubuntu-latest

build-macos:
uses: ./.github/workflows/build.yml
with:
os: macos-latest

test:
needs: build-ubuntu
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
browser: [chromium, firefox] # webkit
include:
- os: macos-latest
browser: webkit

steps:
- uses: actions/checkout@v3
- name: Use Node.js latest
uses: actions/setup-node@v2
with:
node-version: 20.x
- name: Install node dependencies
run: |
npm i -g pnpm
pnpm i
npx playwright install ${{ matrix.browser }}
npx playwright install-deps ${{ matrix.browser }}
- name: Download artifact
uses: actions/download-artifact@v3
with:
name: artifact.tar
- name: Untar files
run: tar -xvf artifact.tar
- name: Test
if: ${{ matrix.os == 'ubuntu-latest' }}
run: |
npx playwright test --browser ${{ matrix.browser }} test/
- name: Test device
if: ${{ matrix.os == 'macos-latest' }}
run: |
npx playwright test --browser ${{ matrix.browser }} test-device/
release:
needs: test
if: ${{ github.ref == 'refs/heads/master' }}
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v3
- name: Download artifact
uses: actions/download-artifact@v3
with:
name: artifact.tar
- name: Untar files
run: tar -xvf artifact.tar
- name: Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
mv dist my-rime-dist
zip -r my-rime-dist.zip my-rime-dist
gh release upload latest my-rime-dist.zip --clobber
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ If you want to deploy schemas dynamically (online, like how you deploy in Deskto
Download latest [artifact](https://github.com/LibreService/my_rime/releases/download/latest/my-rime-dist.zip) built by GitHub Actions.

## Development workflow
My RIME can be built on Linux.
My RIME can be built on Linux and macOS.

### Install node
You may use [nvm](https://github.com/nvm-sh/nvm) to install node.
Expand All @@ -30,6 +30,7 @@ pnpm i
```
### Install build and RIME dependencies
```sh
# Ubuntu
apt install -y \
cmake \
ninja-build \
Expand All @@ -42,6 +43,9 @@ apt install -y \
libleveldb-dev \
libmarisa-dev \
libopencc-dev

# macOS
brew install cmake ninja clang-format
```
### Install emsdk
https://emscripten.org/docs/getting_started/downloads.html
Expand Down
24 changes: 10 additions & 14 deletions opencc_patch
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index ee08591..c347bb8 100644
index ee08591..24da933 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -127,12 +127,21 @@ add_definitions(
@@ -127,12 +127,23 @@ add_definitions(
-DPACKAGE_NAME="${PACKAGE_NAME}"
)

Expand All @@ -11,6 +11,8 @@ index ee08591..c347bb8 100644
+
+if (EMSCRIPTEN)
+ add_definitions(-I"${CMAKE_CURRENT_SOURCE_DIR}/../../../build/sysroot/usr/include")
+else()
+ add_definitions(-I"${CMAKE_CURRENT_SOURCE_DIR}/../../include")
+endif()
+
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
Expand All @@ -25,29 +27,23 @@ index ee08591..c347bb8 100644
if (CMAKE_BUILD_TYPE MATCHES Debug)
add_definitions(-O0 -g3)
endif ()
@@ -196,9 +205,11 @@ endif()
@@ -196,9 +207,6 @@ endif()
######## Subdirectories

add_subdirectory(src)
-add_subdirectory(doc)
-add_subdirectory(data)
-add_subdirectory(test)
+if (NOT EMSCRIPTEN)
+ add_subdirectory(doc)
+ add_subdirectory(data)
+ add_subdirectory(test)
+endif ()

######## Testing

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index c0a0b10..7fa0a4f 100644
index c0a0b10..b8cdc73 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -185,4 +185,6 @@ endif()
@@ -184,5 +184,3 @@ if (ENABLE_BENCHMARK)
endif()

# Subdir

+if (NOT EMSCRIPTEN)
add_subdirectory(tools)
+endif()
-
-add_subdirectory(tools)
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"submodule": "bash scripts/update_submodule.sh",
"worker": "rollup -c rollup.worker-config.js",
"font": "node --loader ts-node/esm scripts/download_font.ts",
"native": "bash scripts/build_native.sh",
"native": "node --loader ts-node/esm scripts/build_native.ts",
"schema": "node --loader ts-node/esm scripts/install_schemas.ts",
"lib": "node --loader ts-node/esm scripts/build_lib.ts",
"lib:boost": "pnpm run lib -- boost",
Expand Down
2 changes: 1 addition & 1 deletion scripts/build_lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ const CMAKE_FIND_ROOT_PATH = `${DESTDIR}/usr`
const CMAKE_DEF = [
'-DCMAKE_INSTALL_PREFIX:PATH=/usr',
`-DCMAKE_BUILD_TYPE:STRING=${BUILD_TYPE}`,
'-DBUILD_TESTING:BOOL=OFF',
'-DBUILD_SHARED_LIBS:BOOL=OFF'
]

Expand Down Expand Up @@ -156,6 +155,7 @@ function buildGlog () {
'-G', 'Ninja',
...CMAKE_DEF,
'-DWITH_GFLAGS:BOOL=OFF',
'-DBUILD_TESTING:BOOL=OFF',
'-DWITH_UNWIND:BOOL=OFF'
], spawnArg))
ensure(spawnSync('cmake', ['--build', dst], spawnArg))
Expand Down
20 changes: 0 additions & 20 deletions scripts/build_native.sh

This file was deleted.

Loading

0 comments on commit 16bedce

Please sign in to comment.