Reduce idle work and disk churn with native resource diagnostics (#2679)
Co-authored-by: codex <[email protected]>
This commit is contained in:
1 parent
3137c2b162
commit
49c0d96edf
122 files changed
+18527
-2203
No files matched your search
@@ -15,9 +15,11 @@ import {
|
||||
createBuildConfig,
|
||||
DESKTOP_ELECTRON_LANGUAGES,
|
||||
DESKTOP_FILE_EXCLUSIONS,
|
||||
DESKTOP_EXTRA_RESOURCES,
|
||||
InvalidMacPasskeyRpDomainError,
|
||||
InvalidMacPasskeyPublishableKeyError,
|
||||
InvalidMockUpdateServerPortError,
|
||||
UnsupportedDesktopBuildArchitectureError,
|
||||
isMacPasskeySigningConfigurationError,
|
||||
LinuxIconResizeError,
|
||||
MacPasskeySigningConfigurationResolutionError,
|
||||
@@ -32,6 +34,8 @@ import {
|
||||
resolveDesktopProductName,
|
||||
resolveDesktopUpdateChannel,
|
||||
resolveDesktopWebAssetBrand,
|
||||
resolveResourceMonitorRustTargets,
|
||||
resourceMonitorExecutableName,
|
||||
resolveGitHubPublishConfig,
|
||||
resolveMockUpdateServerPort,
|
||||
resolveMockUpdateServerUrl,
|
||||
@@ -543,6 +547,26 @@ it.layer(NodeServices.layer)("build-desktop-artifact", (it) => {
|
||||
}).pipe(Effect.provide(ConfigProvider.layer(ConfigProvider.fromEnv({ env: {} })))),
|
||||
);
|
||||
|
||||
it("stages the resource monitor as an external executable resource", () => {
|
||||
assert.deepStrictEqual(DESKTOP_EXTRA_RESOURCES, [
|
||||
{
|
||||
from: "apps/desktop/prod-resources/resource-monitor",
|
||||
to: "resource-monitor",
|
||||
},
|
||||
]);
|
||||
assert.deepStrictEqual(resolveResourceMonitorRustTargets("mac", "universal"), [
|
||||
"aarch64-apple-darwin",
|
||||
"x86_64-apple-darwin",
|
||||
]);
|
||||
assert.deepStrictEqual(resolveResourceMonitorRustTargets("linux", "x64"), [
|
||||
"x86_64-unknown-linux-gnu",
|
||||
]);
|
||||
assert.deepStrictEqual(resolveResourceMonitorRustTargets("win", "arm64"), [
|
||||
"aarch64-pc-windows-msvc",
|
||||
]);
|
||||
assert.equal(resourceMonitorExecutableName("mac"), "t3-resource-monitor");
|
||||
assert.equal(resourceMonitorExecutableName("win"), "t3-resource-monitor.exe");
|
||||
});
|
||||
it("promotes target fff binaries to direct staged dependencies", () => {
|
||||
assert.deepStrictEqual(resolveFffNativeDependencies("mac", "arm64", "0.9.4"), {
|
||||
"@ff-labs/fff-bin-darwin-arm64": "0.9.4",
|
||||
@@ -673,6 +697,32 @@ it.layer(NodeServices.layer)("build-desktop-artifact", (it) => {
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("rejects universal builds on Linux and Windows before staging binaries", () =>
|
||||
Effect.gen(function* () {
|
||||
for (const platform of ["linux", "win"] as const) {
|
||||
const error = yield* Effect.flip(
|
||||
resolveBuildOptions({
|
||||
platform: Option.some(platform),
|
||||
target: Option.none(),
|
||||
arch: Option.some("universal"),
|
||||
buildVersion: Option.none(),
|
||||
outputDir: Option.none(),
|
||||
skipBuild: Option.none(),
|
||||
keepStage: Option.none(),
|
||||
signed: Option.none(),
|
||||
verbose: Option.none(),
|
||||
mockUpdates: Option.none(),
|
||||
mockUpdateServerPort: Option.none(),
|
||||
wslPrebuild: Option.none(),
|
||||
}),
|
||||
);
|
||||
|
||||
assert.instanceOf(error, UnsupportedDesktopBuildArchitectureError);
|
||||
assert.deepStrictEqual(error.supportedArchitectures, ["x64", "arm64"]);
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("preserves explicit false boolean flags over true env defaults", () =>
|
||||
Effect.gen(function* () {
|
||||
const resolved = yield* resolveBuildOptions({
|
||||
|
||||
@@ -94,6 +94,26 @@ interface PlatformConfig {
|
||||
readonly archChoices: ReadonlyArray<typeof BuildArch.Type>;
|
||||
}
|
||||
|
||||
export function resolveResourceMonitorRustTargets(
|
||||
platform: typeof BuildPlatform.Type,
|
||||
arch: typeof BuildArch.Type,
|
||||
): ReadonlyArray<string> {
|
||||
if (platform === "mac") {
|
||||
if (arch === "universal") {
|
||||
return ["aarch64-apple-darwin", "x86_64-apple-darwin"];
|
||||
}
|
||||
return [arch === "arm64" ? "aarch64-apple-darwin" : "x86_64-apple-darwin"];
|
||||
}
|
||||
if (platform === "linux") {
|
||||
return [arch === "arm64" ? "aarch64-unknown-linux-gnu" : "x86_64-unknown-linux-gnu"];
|
||||
}
|
||||
return [arch === "arm64" ? "aarch64-pc-windows-msvc" : "x86_64-pc-windows-msvc"];
|
||||
}
|
||||
|
||||
export function resourceMonitorExecutableName(platform: typeof BuildPlatform.Type): string {
|
||||
return platform === "win" ? "t3-resource-monitor.exe" : "t3-resource-monitor";
|
||||
}
|
||||
|
||||
const PLATFORM_CONFIG: Record<typeof BuildPlatform.Type, PlatformConfig> = {
|
||||
mac: {
|
||||
cliFlag: "--mac",
|
||||
@@ -189,6 +209,19 @@ export class UnsupportedHostBuildPlatformError extends Schema.TaggedErrorClass<U
|
||||
}
|
||||
}
|
||||
|
||||
export class UnsupportedDesktopBuildArchitectureError extends Schema.TaggedErrorClass<UnsupportedDesktopBuildArchitectureError>()(
|
||||
"UnsupportedDesktopBuildArchitectureError",
|
||||
{
|
||||
platform: BuildPlatform,
|
||||
arch: BuildArch,
|
||||
supportedArchitectures: Schema.Array(BuildArch),
|
||||
},
|
||||
) {
|
||||
override get message(): string {
|
||||
return `Unsupported architecture '${this.arch}' for ${this.platform}.`;
|
||||
}
|
||||
}
|
||||
|
||||
const InvalidMockUpdateServerPortReason = Schema.Literals([
|
||||
"not-numeric",
|
||||
"not-integer",
|
||||
@@ -236,6 +269,20 @@ export class BuildCommandFailedError extends Schema.TaggedErrorClass<BuildComman
|
||||
}
|
||||
}
|
||||
|
||||
export class ResourceMonitorBuildOutputMissingError extends Schema.TaggedErrorClass<ResourceMonitorBuildOutputMissingError>()(
|
||||
"ResourceMonitorBuildOutputMissingError",
|
||||
{
|
||||
binaryPath: Schema.String,
|
||||
rustTarget: Schema.String,
|
||||
platform: BuildPlatform,
|
||||
arch: BuildArch,
|
||||
},
|
||||
) {
|
||||
override get message(): string {
|
||||
return `Resource monitor build for ${this.rustTarget} did not produce ${this.binaryPath}.`;
|
||||
}
|
||||
}
|
||||
|
||||
const desktopIconPlatformNames = {
|
||||
mac: "macOS",
|
||||
linux: "Linux",
|
||||
@@ -593,6 +640,12 @@ export const DESKTOP_FILE_EXCLUSIONS = [
|
||||
// The Windows primary backend reads the same files through the asar redirect,
|
||||
// so nothing is duplicated.
|
||||
export const WINDOWS_ASAR_UNPACK = ["apps/server/dist/**", "**/node_modules/**"] as const;
|
||||
export const DESKTOP_EXTRA_RESOURCES = [
|
||||
{
|
||||
from: "apps/desktop/prod-resources/resource-monitor",
|
||||
to: "resource-monitor",
|
||||
},
|
||||
] as const;
|
||||
|
||||
export interface MacPasskeySigningConfiguration {
|
||||
readonly appId: string;
|
||||
@@ -1044,6 +1097,14 @@ export const resolveBuildOptions = Effect.fn("resolveBuildOptions")(function* (
|
||||
const target = mergeOptions(input.target, env.target, PLATFORM_CONFIG[platform].defaultTarget);
|
||||
const defaultArch = yield* getDefaultArch(platform);
|
||||
const arch = mergeOptions(input.arch, env.arch, defaultArch);
|
||||
const supportedArchitectures = PLATFORM_CONFIG[platform].archChoices;
|
||||
if (!supportedArchitectures.includes(arch)) {
|
||||
return yield* new UnsupportedDesktopBuildArchitectureError({
|
||||
platform,
|
||||
arch,
|
||||
supportedArchitectures: [...supportedArchitectures],
|
||||
});
|
||||
}
|
||||
const version = mergeOptions(input.buildVersion, env.version, undefined);
|
||||
const releaseDir = resolveBooleanFlag(input.mockUpdates, env.mockUpdates)
|
||||
? "release-mock"
|
||||
@@ -1117,6 +1178,81 @@ const runCommand = Effect.fn("runCommand")(function* (
|
||||
}
|
||||
});
|
||||
|
||||
const stageResourceMonitor = Effect.fn("stageResourceMonitor")(function* (input: {
|
||||
readonly repoRoot: string;
|
||||
readonly stageResourcesDir: string;
|
||||
readonly platform: typeof BuildPlatform.Type;
|
||||
readonly arch: typeof BuildArch.Type;
|
||||
readonly verbose: boolean;
|
||||
}) {
|
||||
const fs = yield* FileSystem.FileSystem;
|
||||
const path = yield* Path.Path;
|
||||
const manifestPath = path.join(input.repoRoot, "native/resource-monitor/Cargo.toml");
|
||||
const executableName = resourceMonitorExecutableName(input.platform);
|
||||
const rustTargets = resolveResourceMonitorRustTargets(input.platform, input.arch);
|
||||
const builtBinaries: string[] = [];
|
||||
|
||||
for (const rustTarget of rustTargets) {
|
||||
const spawnCommand = yield* resolveSpawnCommand("cargo", [
|
||||
"build",
|
||||
"--locked",
|
||||
"--release",
|
||||
"--manifest-path",
|
||||
manifestPath,
|
||||
"--target",
|
||||
rustTarget,
|
||||
]);
|
||||
yield* runCommand(
|
||||
ChildProcess.make(spawnCommand.command, spawnCommand.args, {
|
||||
cwd: input.repoRoot,
|
||||
shell: spawnCommand.shell,
|
||||
}),
|
||||
{
|
||||
label: `cargo build resource monitor (${rustTarget})`,
|
||||
verbose: input.verbose,
|
||||
},
|
||||
);
|
||||
|
||||
const binaryPath = path.join(
|
||||
input.repoRoot,
|
||||
"native/resource-monitor/target",
|
||||
rustTarget,
|
||||
"release",
|
||||
executableName,
|
||||
);
|
||||
if (!(yield* fs.exists(binaryPath))) {
|
||||
return yield* new ResourceMonitorBuildOutputMissingError({
|
||||
binaryPath,
|
||||
rustTarget,
|
||||
platform: input.platform,
|
||||
arch: input.arch,
|
||||
});
|
||||
}
|
||||
builtBinaries.push(binaryPath);
|
||||
}
|
||||
|
||||
const destinationDirectory = path.join(input.stageResourcesDir, "resource-monitor");
|
||||
const destinationPath = path.join(destinationDirectory, executableName);
|
||||
yield* fs.remove(destinationDirectory, { recursive: true, force: true }).pipe(Effect.ignore);
|
||||
yield* fs.makeDirectory(destinationDirectory, { recursive: true });
|
||||
|
||||
if (builtBinaries.length === 1) {
|
||||
yield* fs.copyFile(builtBinaries[0]!, destinationPath);
|
||||
} else {
|
||||
yield* runCommand(
|
||||
ChildProcess.make("lipo", ["-create", ...builtBinaries, "-output", destinationPath]),
|
||||
{
|
||||
label: "lipo resource monitor universal binary",
|
||||
verbose: input.verbose,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
if (input.platform !== "win") {
|
||||
yield* fs.chmod(destinationPath, 0o755);
|
||||
}
|
||||
});
|
||||
|
||||
function generateMacIconSet(
|
||||
sourcePng: string,
|
||||
targetIcns: string,
|
||||
@@ -1412,6 +1548,7 @@ export const createBuildConfig = Effect.fn("createBuildConfig")(function* (
|
||||
// WINDOWS_ASAR_UNPACK); macOS and Linux stay packed — smart unpack
|
||||
// extracts native libraries, which fff-node finds in app.asar.unpacked.
|
||||
...(platform === "win" ? { asarUnpack: [...WINDOWS_ASAR_UNPACK] } : {}),
|
||||
extraResources: DESKTOP_EXTRA_RESOURCES,
|
||||
};
|
||||
const updateChannel = resolveDesktopUpdateChannel(version);
|
||||
const publishConfig = yield* resolveGitHubPublishConfig(updateChannel);
|
||||
@@ -1691,6 +1828,13 @@ const buildDesktopArtifact = Effect.fn("buildDesktopArtifact")(function* (
|
||||
yield* fs.copy(distDirs.desktopDist, path.join(stageAppDir, "apps/desktop/dist-electron"));
|
||||
yield* fs.copy(distDirs.desktopResources, stageResourcesDir);
|
||||
yield* fs.copy(distDirs.serverDist, path.join(stageAppDir, "apps/server/dist"));
|
||||
yield* stageResourceMonitor({
|
||||
repoRoot,
|
||||
stageResourcesDir,
|
||||
platform: options.platform,
|
||||
arch: options.arch,
|
||||
verbose: options.verbose,
|
||||
});
|
||||
|
||||
yield* assertPlatformBuildResources(
|
||||
options.platform,
|
||||
|
||||
Reference in new issue
Block a user