Skip to content

Commit

Permalink
Update std.tools() and std.toolchain() to sync as a single tarball (
Browse files Browse the repository at this point in the history
  • Loading branch information
kylewlacy authored Jan 20, 2025
1 parent 9c04964 commit 54085f9
Showing 1 changed file with 37 additions and 2 deletions.
39 changes: 37 additions & 2 deletions packages/std/toolchain/native/index.bri
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,9 @@ export const tools = std.memo(async (): Promise<std.Recipe<std.Directory>> => {
MAGIC: { append: [{ path: "share/misc/magic.mgc" }] },
});

return std.sync(tools);
tools = syncTarball(tools);

return tools;
});

/**
Expand Down Expand Up @@ -312,7 +314,7 @@ export const toolchain = std.memo(

toolchain = makePkgConfigPathsRelative(toolchain);

toolchain = std.sync(toolchain);
toolchain = syncTarball(toolchain);

return toolchain;
},
Expand Down Expand Up @@ -428,3 +430,36 @@ function makePkgConfigPathsRelative(
})
.toDirectory();
}

/**
* Sync a recipe by creating an archive of it, then unarchiving it. When
* fetched from the registry, the recipe will be downloaded as a single
* compressed tarball, which may be faster than syncing lots of individual
* files.
*/
function syncTarball(
recipe: std.AsyncRecipe<std.Directory>,
): std.Recipe<std.Directory> {
recipe = std.collectReferences(std.directory({ recipe }));

const tarredRecipe = std
.process({
command: "tar",
args: [
"--zstd",
"-cf",
std.outputPath,
"--hard-dereference",
"-C",
recipe,
".",
],
dependencies: [tar(), zstd()],
})
.toFile();

let untarredRecipe = tarredRecipe.unarchive("tar", "zstd");
untarredRecipe = std.attachResources(untarredRecipe);

return std.castToDirectory(untarredRecipe.get("recipe"));
}

0 comments on commit 54085f9

Please sign in to comment.