From fbdfbcf1a8379e7654208d6c112ee62d8a6cd18f Mon Sep 17 00:00:00 2001 From: Brendan Allan Date: Wed, 13 Nov 2024 22:47:26 +0800 Subject: [PATCH] improve ci & prebuild (#166) * try * pipewire * ffmpeg * more deps * libavfilter * libavdevice * libasound * cleanup --- .../actions/install-desktop-deps/action.yml | 14 +- .github/prebuild.js | 129 +++++++++++------- .github/workflows/debug.yml | 4 +- .github/workflows/publish.yml | 2 +- .gitignore | 5 +- 5 files changed, 98 insertions(+), 56 deletions(-) diff --git a/.github/actions/install-desktop-deps/action.yml b/.github/actions/install-desktop-deps/action.yml index 8e8c89f7..726db4e2 100644 --- a/.github/actions/install-desktop-deps/action.yml +++ b/.github/actions/install-desktop-deps/action.yml @@ -7,5 +7,15 @@ runs: if: ${{ runner.os == 'Linux' }} shell: bash run: | - sudo apt-get update - sudo apt-get install -y libgtk-3-dev libwebkit2gtk-4.0-dev libappindicator3-dev librsvg2-dev patchelf libasound2-dev libxtst-dev libevdev-dev libxdo-dev libsoup-3.0-dev + sudo apt update + sudo apt install libwebkit2gtk-4.1-dev \ + build-essential \ + curl \ + wget \ + file \ + libxdo-dev \ + libssl-dev \ + libayatana-appindicator3-dev \ + librsvg2-dev \ + libpipewire-0.3-dev \ + ffmpeg clang libavcodec-dev libavformat-dev libavutil-dev libavfilter-dev libavdevice-dev pkg-config libasound2-dev diff --git a/.github/prebuild.js b/.github/prebuild.js index 46754bf5..dcddb625 100644 --- a/.github/prebuild.js +++ b/.github/prebuild.js @@ -12,42 +12,16 @@ const keychain = env.APPLE_KEYCHAIN ? `--keychain ${env.APPLE_KEYCHAIN}` : ""; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); -async function symlinkSharedLibsMacOS(nativeDeps) { - // Framework - const framework = path.join(nativeDeps, "Spacedrive.framework"); - - // Sign dylibs (Required for them to work on macOS 13+) - await fs - .readdir(path.join(framework, "Libraries"), { - recursive: true, - withFileTypes: true, - }) - .then((files) => - Promise.all( - files - .filter((entry) => entry.isFile() && entry.name.endsWith(".dylib")) - .map((entry) => - exec( - `codesign ${keychain} -s "${signId}" -f "${path.join( - entry.path, - entry.name - )}"` - ) - ) - ) - ); -} - const __root = path.resolve(path.join(__dirname, "..")); const nativeDeps = path.join(__root, "native-deps"); +const srcTauri = path.join(__root, "apps/desktop/src-tauri"); async function main() { await fs.mkdir(path.join(__root, ".cargo"), { recursive: true }); await fs.writeFile( path.join(__root, ".cargo/config.toml"), - ` -[env] + `[env] FFMPEG_DIR = { force = true, value = "${nativeDeps}" } [target.x86_64-apple-darwin] @@ -65,38 +39,65 @@ rustflags = [ ]` ); + const os = process.argv[2]; + const arch = process.argv[3]; + + if (!os) throw new Error("OS not provided"); + if (!arch) throw new Error("Arch not provided"); + await fs.rm(nativeDeps, { recursive: true, force: true }); await fs.mkdir(nativeDeps, { recursive: true }); - const res = await fetch( - `${NATIVE_DEPS_URL}/${NATIVE_DEPS_ASSETS.Darwin[process.argv[2]]}` - ); + const res = await fetch(`${NATIVE_DEPS_URL}/${NATIVE_DEPS_ASSETS[os][arch]}`); const body = await res.blob(); await fs.writeFile( `${__root}/native-deps.tar.xz`, Buffer.from(await body.arrayBuffer()) ); - await exec(`tar xf ${__root}/native-deps.tar.xz -C ${nativeDeps}`); - await symlinkSharedLibsMacOS(nativeDeps).catch((e) => { - console.error(`Failed to symlink shared libs.`); - throw e; - }); + await exec(`tar xf ${__root}/native-deps.tar.xz -C ${nativeDeps}`); - await fs.writeFile( - `${__root}/apps/desktop/src-tauri/tauri.macos.conf.json`, - JSON.stringify( - { - bundle: { - macOS: { - frameworks: [path.join(nativeDeps, "Spacedrive.framework")], + if (os === "darwin") { + await symlinkSharedLibsMacOS(nativeDeps).catch((e) => { + console.error(`Failed to symlink shared libs.`); + throw e; + }); + + await fs.writeFile( + `${srcTauri}/tauri.macos.conf.json`, + JSON.stringify( + { + bundle: { + macOS: { + frameworks: [path.join(nativeDeps, "Spacedrive.framework")], + }, }, }, - }, - null, - 4 - ) - ); + null, + 4 + ) + ); + } else if (os === "windows") { + const binFiles = await fs.readdir(path.join(nativeDeps, "bin")); + + await fs.writeFile( + `${srcTauri}/tauri.windows.conf.json`, + JSON.stringify( + { + bundle: { + resources: binFiles.filter( + (f) => + f.endsWith(".dll") && (f.startsWith("av") || f.startsWith("sw")) + ), + }, + }, + null, + 4 + ) + ); + + console.log(); + } } main(); @@ -105,8 +106,38 @@ const NATIVE_DEPS_URL = "https://github.com/spacedriveapp/native-deps/releases/latest/download"; const NATIVE_DEPS_ASSETS = { - Darwin: { + darwin: { x86_64: "native-deps-x86_64-darwin-apple.tar.xz", aarch64: "native-deps-aarch64-darwin-apple.tar.xz", }, + windows: { + x86_64: "native-deps-x86_64-windows-gnu.tar.xz", + aarch64: "native-deps-aarch64-windows-gnu.tar.xz", + }, }; + +async function symlinkSharedLibsMacOS(nativeDeps) { + // Framework + const framework = path.join(nativeDeps, "Spacedrive.framework"); + + // Sign dylibs (Required for them to work on macOS 13+) + await fs + .readdir(path.join(framework, "Libraries"), { + recursive: true, + withFileTypes: true, + }) + .then((files) => + Promise.all( + files + .filter((entry) => entry.isFile() && entry.name.endsWith(".dylib")) + .map((entry) => + exec( + `codesign ${keychain} -s "${signId}" -f "${path.join( + entry.path, + entry.name + )}"` + ) + ) + ) + ); +} diff --git a/.github/workflows/debug.yml b/.github/workflows/debug.yml index 10aad21a..2872fa99 100644 --- a/.github/workflows/debug.yml +++ b/.github/workflows/debug.yml @@ -68,7 +68,7 @@ jobs: working-directory: apps/desktop run: | export TARGET_TRIPLE=aarch64-apple-darwin - node ${{ github.workspace }}/.github/prebuild.js aarch64 + node ${{ github.workspace }}/.github/prebuild.js darwin aarch64 pnpm tauri build --target aarch64-apple-darwin --debug env: CI: false @@ -90,4 +90,4 @@ jobs: with: name: debug-build-aarch64-apple-darwin path: apps/desktop/src-tauri/target/aarch64-apple-darwin/debug/bundle/**/*.app - if-no-files-found: error \ No newline at end of file + if-no-files-found: error diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 1a8c8d75..cbc5895f 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -146,7 +146,7 @@ jobs: working-directory: apps/desktop run: | export TARGET_TRIPLE=${{ matrix.settings.target }} - node ${{ github.workspace }}/.github/prebuild.js ${{ matrix.settings.prebuild }} + node ${{ github.workspace }}/.github/prebuild.js darwin ${{ matrix.settings.prebuild }} pnpm tauri build --target ${{ matrix.settings.target }} --config src-tauri/tauri.conf.prod.json env: # https://github.com/tauri-apps/tauri-action/issues/740 diff --git a/.gitignore b/.gitignore index cfed069c..d1b88374 100644 --- a/.gitignore +++ b/.gitignore @@ -32,5 +32,6 @@ pnpm-lock.yaml .zed .output .vinxi -native-deps -apps/storybook/storybook-static \ No newline at end of file +native-deps* +apps/storybook/storybook-static +tauri.*.conf.json