mirror of
https://github.com/spacedriveapp/spacedrive.git
synced 2026-10-10 19:41:36 -04:00
* Move postinstall script to a preprep script - Fix libheif crate failing to build with our libheif - Rework CI due to postinstall to preprep changes * Linux heif build script + Update webp * Fix ctrl+c/ctrl+v bug * Improve libheif linux script - Add support for linux aarch64 - Add CI workflow to build libheif for linux - Some other misc fixes * Fix libheif CI requires sudo * Fix wrong path for libheif build.rs override in Windows * Fix wrong path manipulations in libheif build script * 🤦 * Use ubuntu-latest in libheif action - Specify glib version in target triple to support old distros - Fix libheif artifact publishing * Fix artifact upload path again * Add musl support for libheif - Remove unused files from libheif artifact - Add setup logic for libheif in postinstall script * Build libheif for linux as a shared lib * Fix meson not building the correct arch - Add logic to get git branch from githubs CI env vars * libheif finnaly works on linux - Make spacedrive binary rpath point to where appimage and deb expects our libs to be - Add some logic to tauri.js to convince tauri to bundle our shared libs - Work-around appimage bundling step breaking sometimes - Add logic to handle sigint in tauri.js to ensure we clean up after ourselves - Rename postinstall.mjs to setup.mjs - Add logic to setup.mjs to point our dev build to our shared libs in linux * Fix windows dekstop dev - Rename setup.mjs to preprep.mjs * test cache-factory * Fix preprep script not parsing the cross compilation target triple and always using the host info to download dependencies - Fix action env vars not being correctly passed - Remove possibility to pass multiple targests to rust action * Don't compile mobile crates on desktop targets * Remove cache-factory pull_request trigger * remove patched tauri cli * Use git plumbing command to get remote branch name - Fallback to reading .git/HEAD if remote name was not retrieved * fix type --------- Co-authored-by: Brendan Allan <brendonovich@outlook.com>
194 lines
5.8 KiB
JavaScript
194 lines
5.8 KiB
JavaScript
const fs = require('node:fs');
|
|
const path = require('node:path');
|
|
|
|
const toml = require('@iarna/toml');
|
|
const semver = require('semver');
|
|
|
|
const { spawn } = require('./spawn.js');
|
|
|
|
const workspace = path.resolve(__dirname, '../../../../');
|
|
const cargoConfig = toml.parse(
|
|
fs.readFileSync(path.resolve(workspace, '.cargo/config.toml'), { encoding: 'binary' })
|
|
);
|
|
if (cargoConfig.env && typeof cargoConfig.env === 'object')
|
|
for (const [name, value] of Object.entries(cargoConfig.env))
|
|
if (!process.env[name]) process.env[name] = value;
|
|
|
|
const toRemove = [];
|
|
const [_, __, ...args] = process.argv;
|
|
|
|
if (args.length === 0) args.push('build');
|
|
|
|
const tauriConf = JSON.parse(
|
|
fs.readFileSync(path.resolve(__dirname, '..', 'tauri.conf.json'), 'utf-8')
|
|
);
|
|
|
|
const framework = path.join(workspace, 'target/Frameworks');
|
|
|
|
switch (args[0]) {
|
|
case 'dev': {
|
|
if (process.platform === 'win32') setupSharedLibs('dll', path.join(framework, 'bin'), true);
|
|
break;
|
|
}
|
|
case 'build': {
|
|
if (
|
|
!process.env.NODE_OPTIONS ||
|
|
!process.env.NODE_OPTIONS.includes('--max_old_space_size')
|
|
) {
|
|
process.env.NODE_OPTIONS = `--max_old_space_size=4096 ${
|
|
process.env.NODE_OPTIONS ?? ''
|
|
}`;
|
|
}
|
|
|
|
if (args.findIndex((e) => e === '-c' || e === '--config') !== -1) {
|
|
throw new Error('Custom tauri build config is not supported.');
|
|
}
|
|
|
|
const targets = args
|
|
.filter((_, index, args) => {
|
|
if (index === 0) return false;
|
|
const previous = args[index - 1];
|
|
return previous === '-t' || previous === '--target';
|
|
})
|
|
.flatMap((target) => target.split(','));
|
|
|
|
const tauriPatch = {
|
|
tauri: { bundle: { macOS: {}, resources: [] } }
|
|
};
|
|
|
|
switch (process.platform) {
|
|
case 'darwin': {
|
|
// ARM64 support was added in macOS 11, but we need at least 11.2 due to our ffmpeg build
|
|
let macOSMinimumVersion = tauriConf?.tauri?.bundle?.macOS?.minimumSystemVersion;
|
|
let macOSArm64MinimumVersion = '11.2';
|
|
if (
|
|
(targets.includes('aarch64-apple-darwin') ||
|
|
(targets.length === 0 && process.arch === 'arm64')) &&
|
|
(macOSMinimumVersion == null ||
|
|
semver.lt(
|
|
semver.coerce(macOSMinimumVersion),
|
|
semver.coerce(macOSArm64MinimumVersion)
|
|
))
|
|
) {
|
|
macOSMinimumVersion = macOSArm64MinimumVersion;
|
|
console.log(
|
|
`aarch64-apple-darwin target detected, setting minimum system version to ${macOSMinimumVersion}`
|
|
);
|
|
}
|
|
|
|
if (macOSMinimumVersion) {
|
|
process.env.MACOSX_DEPLOYMENT_TARGET = macOSMinimumVersion;
|
|
tauriPatch.tauri.bundle.macOS.minimumSystemVersion = macOSMinimumVersion;
|
|
}
|
|
|
|
// Point tauri to our ffmpeg framework
|
|
tauriPatch.tauri.bundle.macOS.frameworks = [
|
|
path.join(workspace, 'target/Frameworks/FFMpeg.framework')
|
|
];
|
|
|
|
// Configure DMG background
|
|
process.env.BACKGROUND_FILE = path.resolve(__dirname, '..', 'dmg-background.png');
|
|
process.env.BACKGROUND_FILE_NAME = path.basename(process.env.BACKGROUND_FILE);
|
|
process.env.BACKGROUND_CLAUSE = `set background picture of opts to file ".background:${process.env.BACKGROUND_FILE_NAME}"`;
|
|
|
|
if (!fs.existsSync(process.env.BACKGROUND_FILE))
|
|
console.warn(
|
|
`WARNING: DMG background file not found at ${process.env.BACKGROUND_FILE}`
|
|
);
|
|
|
|
break;
|
|
}
|
|
case 'linux':
|
|
fs.rmSync(path.join(workspace, 'target/release/bundle/appimage'), {
|
|
recursive: true,
|
|
force: true
|
|
});
|
|
// Point tauri to the ffmpeg DLLs
|
|
tauriPatch.tauri.bundle.resources.push(
|
|
...setupSharedLibs('so', path.join(framework, 'lib'))
|
|
);
|
|
break;
|
|
case 'win32':
|
|
// Point tauri to the ffmpeg DLLs
|
|
tauriPatch.tauri.bundle.resources.push(
|
|
...setupSharedLibs('dll', path.join(framework, 'bin'))
|
|
);
|
|
break;
|
|
}
|
|
|
|
toRemove.push(
|
|
...tauriPatch.tauri.bundle.resources.map((file) =>
|
|
path.join(workspace, 'apps/desktop/src-tauri', file)
|
|
)
|
|
);
|
|
|
|
const tauriPatchConf = path.resolve(__dirname, '..', 'tauri.conf.patch.json');
|
|
fs.writeFileSync(tauriPatchConf, JSON.stringify(tauriPatch, null, 2));
|
|
|
|
toRemove.push(tauriPatchConf);
|
|
args.splice(1, 0, '-c', tauriPatchConf);
|
|
}
|
|
}
|
|
|
|
process.on('SIGINT', () => {
|
|
for (const file of toRemove)
|
|
try {
|
|
fs.unlinkSync(file);
|
|
} catch (e) {}
|
|
});
|
|
|
|
let code = 0;
|
|
spawn('pnpm', ['exec', 'tauri', ...args])
|
|
.catch((exitCode) => {
|
|
if (args[0] === 'build' || process.platform === 'linux') {
|
|
// Work around appimage buindling not working sometimes
|
|
appimageDir = path.join(workspace, 'target/release/bundle/appimage');
|
|
appDir = path.join(appimageDir, 'spacedrive.AppDir');
|
|
if (
|
|
fs.existsSync(path.join(appimageDir, 'build_appimage.sh')) &&
|
|
fs.existsSync(appDir) &&
|
|
!fs.readdirSync(appimageDir).filter((file) => file.endsWith('.AppImage')).length
|
|
) {
|
|
process.chdir(appimageDir);
|
|
fs.rmSync(appDir, { recursive: true, force: true });
|
|
return spawn('bash', ['build_appimage.sh']).catch((exitCode) => {
|
|
code = exitCode;
|
|
console.error(`tauri ${args[0]} failed with exit code ${exitCode}`);
|
|
});
|
|
}
|
|
}
|
|
|
|
code = exitCode;
|
|
console.error(`tauri ${args[0]} failed with exit code ${exitCode}`);
|
|
console.error(
|
|
`If you got an error related to FFMpeg or Protoc/Protobuf you may need to re-run \`pnpm i\``
|
|
);
|
|
})
|
|
.finally(() => {
|
|
for (const file of toRemove)
|
|
try {
|
|
fs.unlinkSync(file);
|
|
} catch (e) {}
|
|
|
|
process.exit(code);
|
|
});
|
|
|
|
function setupSharedLibs(sufix, binDir, dev = false) {
|
|
const sharedLibs = fs
|
|
.readdirSync(binDir)
|
|
.filter((file) => file.endsWith(`.${sufix}`) || file.includes(`.${sufix}.`));
|
|
|
|
let targetDir = path.join(workspace, 'apps/desktop/src-tauri');
|
|
if (dev) {
|
|
targetDir = path.join(workspace, 'target/debug');
|
|
// Ensure the target/debug directory exists
|
|
fs.mkdirSync(targetDir, { recursive: true });
|
|
}
|
|
|
|
// Copy all shared libs to targetDir
|
|
for (const dll of sharedLibs)
|
|
fs.copyFileSync(path.join(binDir, dll), path.join(targetDir, dll));
|
|
|
|
return sharedLibs;
|
|
}
|