Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve ci & prebuild #166

Merged
merged 8 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions .github/actions/install-desktop-deps/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
129 changes: 80 additions & 49 deletions .github/prebuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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();
Expand All @@ -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
)}"`
)
)
)
);
}
4 changes: 2 additions & 2 deletions .github/workflows/debug.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
if-no-files-found: error
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ pnpm-lock.yaml
.zed
.output
.vinxi
native-deps
apps/storybook/storybook-static
native-deps*
apps/storybook/storybook-static
tauri.*.conf.json
Loading