dasimmet/zigsh
No description provided.
Even though zig is great at building everything from source, sometimes a build tool is easier to be reused as a binary distribution, especially if hermetic built versions are available.
We can use lazy Dependencies to switch the required binary
this build.zig offers a BunModuleStep to bundle a javascript file with its dependencies
on the build graph.
It works by creating a package.json
in the zig's build cache,
then running bun install
and bun bun
to download and install the js dependencies.
The output is a std.Build.LazyPath
that can be reused on other build steps
// build.zig
const zigsh = @import("zigsh");
// pub fn build(...
const bundled_js = zigsh.BunModuleStep.add(b, .{
.name = "index.js",
.out_basename = "index.js",
.root_source_file = b.path("src/js/index.js"), // input js file
.optimize = optimize, //
.verbose = b.verbose,
.sourcemap = true,
.dependencies = &.{
.{
.name = "hello-world-npm",
.version = zigsh.semver("1.1.1"),
},
},
});
const bundled_js_path: std.Build.LazyPath = bundled_js.bun.output;