diff --git a/.github/actions/build-rust/action.yml b/.github/actions/build-rust/action.yml new file mode 100644 index 0000000000..4549065f7e --- /dev/null +++ b/.github/actions/build-rust/action.yml @@ -0,0 +1,47 @@ +name: 'AFFiNE Rust build' +description: 'Rust build setup, including cache configuration' +inputs: + target: + description: 'Cargo target' + required: true + +runs: + using: 'composite' + steps: + - name: Setup Rust + uses: dtolnay/rust-toolchain@stable + with: + toolchain: stable + targets: ${{ inputs.target }} + + - name: Cache cargo + uses: actions/cache@v3 + with: + path: | + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + .cargo-cache + target/${{ inputs.target }} + key: stable-${{ inputs.target }}-cargo-cache + + - name: Build + if: ${{ inputs.target != 'x86_64-unknown-linux-gnu' && inputs.target != 'aarch64-unknown-linux-gnu' }} + shell: bash + run: yarn workspace @affine/native build --target ${{ inputs.target }} + + - name: Build + if: ${{ inputs.target == 'x86_64-unknown-linux-gnu' }} + uses: addnab/docker-run-action@v3 + with: + image: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian + options: --user 0:0 -v ${{ github.workspace }}/.cargo-cache/git/db:/usr/local/cargo/git/db -v ${{ github.workspace }}/.cargo/registry/cache:/usr/local/cargo/registry/cache -v ${{ github.workspace }}/.cargo/registry/index:/usr/local/cargo/registry/index -v ${{ github.workspace }}:/build -w /build + run: yarn workspace @affine/native build --target ${{ inputs.target }} + + - name: Build + if: ${{ inputs.target == 'aarch64-unknown-linux-gnu' }} + uses: addnab/docker-run-action@v3 + with: + image: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian-aarch64 + options: --user 0:0 -v ${{ github.workspace }}/.cargo-cache/git/db:/usr/local/cargo/git/db -v ${{ github.workspace }}/.cargo/registry/cache:/usr/local/cargo/registry/cache -v ${{ github.workspace }}/.cargo/registry/index:/usr/local/cargo/registry/index -v ${{ github.workspace }}:/build -w /build + run: yarn workspace @affine/native build --target ${{ inputs.target }} diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 200236cc84..7d245cd025 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -20,6 +20,12 @@ on: - .github/** - '!.github/workflows/build.yml' +env: + CARGO_BUILD_INCREMENTAL: 'false' + DEBUG: napi:* + APP_NAME: affine + MACOSX_DEPLOYMENT_TARGET: '10.13' + jobs: lint: name: Lint @@ -273,7 +279,7 @@ jobs: - name: Upload test results if: ${{ failure() }} - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: name: test-results-e2e-${{ matrix.shard }} path: ./test-results @@ -281,17 +287,41 @@ jobs: dekstop-test: name: Desktop Test - runs-on: ubuntu-latest + runs-on: ${{ matrix.spec.os }} environment: development strategy: fail-fast: false # all combinations: macos-latest x64, macos-latest arm64, windows-latest x64, ubuntu-latest x64 matrix: spec: - - { os: macos-latest, platform: macos, arch: x64 } - - { os: macos-latest, platform: macos, arch: arm64 } - - { os: ubuntu-latest, platform: linux, arch: x64 } - - { os: windows-latest, platform: windows, arch: x64 } + - { + os: macos-latest, + platform: macos, + arch: x64, + target: x86_64-apple-darwin, + test: true, + } + - { + os: macos-latest, + platform: macos, + arch: arm64, + target: aarch64-apple-darwin, + test: false, + } + - { + os: ubuntu-latest, + platform: linux, + arch: x64, + target: x86_64-unknown-linux-gnu, + test: true, + } + - { + os: windows-latest, + platform: windows, + arch: x64, + target: x86_64-pc-windows-msvc, + test: true, + } needs: [build, build-electron] steps: - uses: actions/checkout@v3 @@ -299,6 +329,10 @@ jobs: uses: ./.github/actions/setup-node with: playwright-install: true + - name: Build AFFiNE native + uses: ./.github/actions/build-rust + with: + target: ${{ matrix.spec.target }} - name: Download Ubuntu desktop artifact uses: actions/download-artifact@v3 with: @@ -316,12 +350,18 @@ jobs: working-directory: apps/electron - name: Run desktop tests + if: ${{ matrix.spec.test && matrix.spec.os == 'ubuntu-latest' }} run: xvfb-run --auto-servernum --server-args="-screen 0 1280x960x24" -- yarn test working-directory: apps/electron + - name: Run desktop tests + if: ${{ matrix.spec.test && matrix.spec.os != 'ubuntu-latest' }} + run: yarn test + working-directory: apps/electron + - name: Upload test results if: ${{ failure() }} - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: name: test-results-e2e-${{ matrix.shard }} path: ./test-results diff --git a/.github/workflows/release-desktop-app.yml b/.github/workflows/release-desktop-app.yml index da77b8ebda..1d10a78fa2 100644 --- a/.github/workflows/release-desktop-app.yml +++ b/.github/workflows/release-desktop-app.yml @@ -36,6 +36,10 @@ concurrency: env: BUILD_TYPE: ${{ github.event.inputs.build-type }} + CARGO_BUILD_INCREMENTAL: 'false' + DEBUG: napi:* + APP_NAME: affine + MACOSX_DEPLOYMENT_TARGET: '10.13' jobs: before-make: @@ -89,10 +93,30 @@ jobs: # all combinations: macos-latest x64, macos-latest arm64, windows-latest x64, ubuntu-latest x64 matrix: spec: - - { os: macos-latest, platform: macos, arch: x64 } - - { os: macos-latest, platform: macos, arch: arm64 } - - { os: ubuntu-latest, platform: linux, arch: x64 } - - { os: windows-latest, platform: windows, arch: x64 } + - { + os: macos-latest, + platform: macos, + arch: x64, + target: x86_64-apple-darwin, + } + - { + os: macos-latest, + platform: macos, + arch: arm64, + target: aarch64-apple-darwin, + } + - { + os: ubuntu-latest, + platform: linux, + arch: x64, + target: x86_64-unknown-linux-gnu, + } + - { + os: windows-latest, + platform: windows, + arch: x64, + target: x86_64-pc-windows-msvc, + } runs-on: ${{ matrix.spec.os }} needs: before-make env: @@ -104,6 +128,10 @@ jobs: - uses: actions/checkout@v3 - name: Setup Node.js uses: ./.github/actions/setup-node + - name: Build AFFiNE native + uses: ./.github/actions/build-rust + with: + target: ${{ matrix.spec.target }} - uses: actions/download-artifact@v3 with: name: before-make-web-static diff --git a/Cargo.lock b/Cargo.lock index 3393e7865b..8992cc4c9d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3,7 +3,7 @@ version = 3 [[package]] -name = "affine_octobase" +name = "affine_native" version = "0.0.0" dependencies = [ "anyhow", diff --git a/Cargo.toml b/Cargo.toml index 4246cf084e..8b5f358fa1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,2 +1,8 @@ [workspace] members = ["./packages/native"] + +[profile.release] +lto = true +codegen-units = 1 +opt-level = 3 +strip = "symbols" diff --git a/apps/electron/tests/fixture.ts b/apps/electron/tests/fixture.ts index 03ccad6d30..ed600e6e2d 100644 --- a/apps/electron/tests/fixture.ts +++ b/apps/electron/tests/fixture.ts @@ -54,9 +54,16 @@ export const test = base.extend<{ electronApp: async ({}, use) => { // a random id to avoid conflicts between tests const id = generateUUID(); + const ext = process.platform === 'win32' ? '.cmd' : ''; const electronApp = await electron.launch({ args: [resolve(__dirname, '..'), '--app-name', 'affine-test-' + id], - executablePath: resolve(__dirname, '../node_modules/.bin/electron'), + executablePath: resolve( + __dirname, + '..', + 'node_modules', + '.bin', + `electron${ext}` + ), colorScheme: 'light', }); await use(electronApp); diff --git a/packages/native/Cargo.toml b/packages/native/Cargo.toml index ff2251fe19..28c13c05a6 100644 --- a/packages/native/Cargo.toml +++ b/packages/native/Cargo.toml @@ -1,6 +1,6 @@ [package] edition = "2021" -name = "affine_octobase" +name = "affine_native" version = "0.0.0" [lib]