-
Notifications
You must be signed in to change notification settings - Fork 329
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f2289ae
commit 462bbf5
Showing
4 changed files
with
188 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[env] | ||
FFMPEG_DIR = { relative = true, force = true, value = "target/native-deps" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,8 @@ | |
"db:generate": "dotenv -e .env -- pnpm --dir packages/database db:generate", | ||
"db:studio": "dotenv -e .env -- pnpm --dir packages/database db:studio", | ||
"tauri:build": "dotenv -e .env -- pnpm --dir apps/desktop tauri build --verbose", | ||
"typecheck": "pnpm tsc -b" | ||
"typecheck": "pnpm tsc -b", | ||
"cap-setup": "node scripts/setup.js" | ||
}, | ||
"devDependencies": { | ||
"@turbo/gen": "^1.9.7", | ||
|
@@ -31,4 +32,4 @@ | |
"@kobalte/[email protected]": "patches/@[email protected]" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,181 @@ | ||
// @ts-check | ||
import * as fs from "node:fs/promises"; | ||
import * as path from "node:path"; | ||
import { fileURLToPath } from "node:url"; | ||
import { exec as execCb } from "node:child_process"; | ||
import { env } from "node:process"; | ||
import { promisify } from "node:util"; | ||
|
||
const exec = promisify(execCb); | ||
|
||
const __filename = fileURLToPath(import.meta.url); | ||
const __dirname = path.dirname(__filename); | ||
|
||
const __root = path.resolve(path.join(__dirname, "..")); | ||
const targetDir = `${__root}/target`; | ||
|
||
async function main() { | ||
if (process.platform === "darwin") { | ||
const NATIVE_DEPS_URL = | ||
"https://github.com/spacedriveapp/native-deps/releases/latest/download"; | ||
|
||
const NATIVE_DEPS_ASSETS = { | ||
darwin: { | ||
x86_64: "native-deps-x86_64-darwin-apple.tar.xz", | ||
aarch64: "native-deps-aarch64-darwin-apple.tar.xz", | ||
}, | ||
}; | ||
|
||
const nativeDepsTar = `${targetDir}/native-deps.tar.xz`; | ||
if (!(await fileExists(nativeDepsTar))) { | ||
const nativeDepsBytes = await fetch( | ||
`${NATIVE_DEPS_URL}/${NATIVE_DEPS_ASSETS.darwin.aarch64}` | ||
) | ||
.then((r) => r.blob()) | ||
.then((b) => b.arrayBuffer()); | ||
await fs.writeFile(nativeDepsTar, Buffer.from(nativeDepsBytes)); | ||
console.log("Downloaded native deps"); | ||
} else console.log("Using cached native-deps.tar.xz"); | ||
|
||
const nativeDepsDir = `${targetDir}/native-deps`; | ||
if (!(await fileExists(nativeDepsDir))) { | ||
await fs.mkdir(nativeDepsDir, { recursive: true }); | ||
await exec(`tar xf ${targetDir}/native-deps.tar.xz -C ${nativeDepsDir}`); | ||
console.log("Extracted native-deps"); | ||
} else console.log("Using cached native-deps"); | ||
|
||
const frameworkDir = path.join(nativeDepsDir, "Spacedrive.framework"); | ||
await trimMacOSFramework(frameworkDir); | ||
console.log("Trimmed .framework"); | ||
|
||
console.log("Signing .framework libraries"); | ||
await signMacOSFrameworkLibs(frameworkDir); | ||
console.log("Signed .framework libraries"); | ||
|
||
// alternative to specifying dylibs as linker args | ||
for (const name of await fs.readdir(`${nativeDepsDir}/lib`)) { | ||
await fs.copyFile( | ||
`${nativeDepsDir}/lib/${name}`, | ||
`${targetDir}/debug/${name}` | ||
); | ||
} | ||
console.log("Copied ffmepg dylibs to target/debug"); | ||
} else if (process.platform === "win32") { | ||
const FFMPEG_ZIP_NAME = "ffmpeg-7.1-full_build-shared"; | ||
const FFMPEG_ZIP_URL = `https://github.com/GyanD/codexffmpeg/releases/download/7.1/${FFMPEG_ZIP_NAME}.zip`; | ||
|
||
const ffmpegZip = `${targetDir}/ffmpeg.zip`; | ||
if (!(await fileExists(ffmpegZip))) { | ||
const ffmpegZipBytes = await fetch(FFMPEG_ZIP_URL) | ||
.then((r) => r.blob()) | ||
.then((b) => b.arrayBuffer()); | ||
await fs.writeFile(ffmpegZip, Buffer.from(ffmpegZipBytes)); | ||
console.log("Downloaded ffmpeg.zip"); | ||
} else console.log("Using cached ffmpeg.zip"); | ||
|
||
const ffmpegDir = `${targetDir}/ffmepg`; | ||
if (!(await fileExists(ffmpegDir))) { | ||
await exec(`tar xf ${ffmpegZip} -C ${targetDir}`); | ||
await fs.rename(`${targetDir}/${FFMPEG_ZIP_NAME}`, ffmpegDir); | ||
console.log("Extracted ffmpeg"); | ||
} else console.log("Using cached ffmpeg"); | ||
|
||
// alternative to adding ffmpeg/bin to PATH | ||
for (const name of await fs.readdir(`${ffmpegDir}/bin`)) { | ||
await fs.copyFile( | ||
`${ffmpegDir}/bin/${name}`, | ||
`${targetDir}/debug/${name}` | ||
); | ||
} | ||
console.log("Copied ffmepg dylibs to target/debug"); | ||
|
||
if (!(await fileExists(`${targetDir}/native-deps`))) | ||
await fs.mkdir(`${targetDir}/native-deps`, { recursive: true }); | ||
|
||
await fs.cp(`${ffmpegDir}/lib`, `${targetDir}/native-deps/lib`, { | ||
recursive: true, | ||
force: true, | ||
}); | ||
await fs.cp(`${ffmpegDir}/include`, `${targetDir}/native-deps/include`, { | ||
recursive: true, | ||
force: true, | ||
}); | ||
console.log("Copied ffmpeg/lib and ffmpeg/include to target/native-deps"); | ||
} | ||
} | ||
|
||
main(); | ||
|
||
async function trimMacOSFramework(frameworkDir) { | ||
const headersDir = path.join(frameworkDir, "Headers"); | ||
const librariesDir = path.join(frameworkDir, "Libraries"); | ||
|
||
const libraries = await fs.readdir(librariesDir); | ||
|
||
const unnecessaryLibraries = libraries.filter( | ||
(v) => | ||
!( | ||
v.startsWith("libav") || | ||
v.startsWith("libsw") || | ||
v.startsWith("libpostproc") | ||
) | ||
); | ||
|
||
for (const lib of unnecessaryLibraries) { | ||
await fs.rm(path.join(librariesDir, lib), { recursive: true }); | ||
} | ||
|
||
const headers = await fs.readdir(headersDir); | ||
|
||
const unnecessaryHeaders = headers.filter( | ||
(v) => | ||
!( | ||
v.startsWith("libav") || | ||
v.startsWith("libsw") || | ||
v.startsWith("libpostproc") | ||
) | ||
); | ||
|
||
for (const header of unnecessaryHeaders) { | ||
await fs.rm(path.join(headersDir, header), { recursive: true }); | ||
} | ||
|
||
const modelsPath = path.join(frameworkDir, "Resources", "Models"); | ||
if (await fileExists(modelsPath)) | ||
await fs.rm(modelsPath, { | ||
recursive: true, | ||
}); | ||
} | ||
|
||
async function signMacOSFrameworkLibs(frameworkDir) { | ||
const signId = env.APPLE_SIGNING_IDENTITY || "-"; | ||
const keychain = env.APPLE_KEYCHAIN ? `--keychain ${env.APPLE_KEYCHAIN}` : ""; | ||
|
||
// Sign dylibs (Required for them to work on macOS 13+) | ||
await fs | ||
.readdir(path.join(frameworkDir, "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 | ||
)}"` | ||
) | ||
) | ||
) | ||
); | ||
} | ||
|
||
async function fileExists(path) { | ||
return await fs | ||
.access(path) | ||
.then(() => true) | ||
.catch(() => false); | ||
} |
462bbf5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
cap-web – ./
www.cap.so
cap-web-mc-ilroy.vercel.app
cap-web-nu.vercel.app
cap-web-git-main-mc-ilroy.vercel.app
cap.so