Skip to content

Commit

Permalink
build wasm from source
Browse files Browse the repository at this point in the history
  • Loading branch information
gwenzek committed Sep 13, 2024
1 parent 57f6ebf commit dbb04b5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
6 changes: 1 addition & 5 deletions 01-PREPARE-FOR-EDITS.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ curl https://ziglang.org/documentation/0.13.0/std/main.wasm -s -o WORKSPACE/main
curl https://ziglang.org/documentation/0.13.0/std/main.js -s -o WORKSPACE/main.js

# link-in the assets and layouts
for d in assets layouts ; do
for d in assets layouts zig_docs; do
if [ ! -h ${WORKSPACE}/$d ] ; then
ln -s ../$d ${WORKSPACE}/$d
fi
Expand Down Expand Up @@ -42,7 +42,3 @@ for i in $(find content -iname '*.smd') ; do
mkdir -p $(dirname $SMD_DEST)
cat $SMD_SOURCE $MD_SOURCE > $SMD_DEST
done

# finally, copy over build.zig, build.zig.zon because zine does not like
# subdirs
cp -v ./build.zig* $WORKSPACE/
2 changes: 2 additions & 0 deletions 02-BUILD.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ cd zml
# resulting in broken links + polluting the search bar.
tar -cf sources.tar zml/*.zig zml/**/*.zig
cd ..

cp -f ./zml/sources.tar WORKSPACE/
cp -v ./build.zig* WORKSPACE/

cd WORKSPACE
echo "Starting Zine build..."
Expand Down
21 changes: 20 additions & 1 deletion build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,25 @@ const std = @import("std");
const zine = @import("zine");

pub fn build(b: *std.Build) !void {
const wasm_target = b.resolveTargetQuery(.{
.cpu_arch = .wasm32,
.os_tag = .freestanding,
});

// Vendored version of https://github.com/ziglang/zig/tree/0.13.0/lib/docs/wasm
const docs_wasm = b.addExecutable(.{
.name = "main",
.target = wasm_target,
.optimize = .Debug,
.root_source_file = .{ .cwd_relative = "zig_docs/main.zig" },
});
docs_wasm.entry = .disabled;
docs_wasm.rdynamic = true;
const Walk = b.addModule("Walk", .{
.root_source_file = .{ .cwd_relative = "zig_docs/Walk.zig" },
});
docs_wasm.root_module.addImport("Walk", Walk);

zine.website(b, .{
.title = "ZML Documentation Website",
.host_url = "https://docs.zml.ai",
Expand All @@ -13,7 +32,7 @@ pub fn build(b: *std.Build) !void {
"zml.no_light.svg",
},
.build_assets = &.{
staticAsset(b, "main.wasm"),
.{ .name = "main.wasm", .lp = docs_wasm.getEmittedBin(), .install_path = "main.wasm", .install_always = true },
staticAsset(b, "main.js"),
staticAsset(b, "sources.tar"),
},
Expand Down

0 comments on commit dbb04b5

Please sign in to comment.