Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 32 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
on:
- push
push:
branches:
- "**"

permissions:
contents: read

jobs:
build:
Expand All @@ -9,7 +14,32 @@ jobs:
- uses: DeterminateSystems/nix-installer-action@main
- uses: DeterminateSystems/magic-nix-cache-action@main
- run: nix build . --print-build-logs
- run: cp -L result linux.tgz
- uses: actions/upload-artifact@v4
with:
name: kernel
path: result
path: linux.tgz

publish:
if: github.ref == 'refs/heads/main'
needs: build
runs-on: ubuntu-24.04
permissions:
contents: read
id-token: write
steps:
- uses: actions/download-artifact@v4
with:
name: kernel
- uses: actions/setup-node@v4
with:
node-version: 24
registry-url: https://registry.npmjs.org
package-manager-cache: false
- run: |
version="0.0.0-${GITHUB_SHA::8}"
if npm view "@tombl/linux@$version" version >/dev/null 2>&1; then
echo "@tombl/linux@$version is already published"
else
npm publish ./linux.tgz --access public --tag snapshot
fi
10 changes: 8 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
let
pkgs = nixpkgs.legacyPackages.${system};
llvm = pkgs.llvmPackages_19;
sourceRev = self.rev or self.dirtyRev or "unknown";
npmVersion = "0.0.0-${builtins.substring 0 8 sourceRev}";
in
{
default = pkgs.stdenvNoCC.mkDerivation {
Expand All @@ -41,6 +43,7 @@
wabt
esbuild
typescript
nodejs

just
miniserve
Expand All @@ -52,13 +55,16 @@
configurePhase = "make HOSTCC=$HOSTCC -j$NIX_BUILD_CORES defconfig";
buildPhase = "
# this is a horrible dirty hack but there's some non-deterministic build failure
built=0
for i in $(seq 1 3); do
if make HOSTCC=$HOSTCC -j$NIX_BUILD_CORES -C tools/wasm; then
if make HOSTCC=$HOSTCC -j$NIX_BUILD_CORES -C tools/wasm PACKAGE_VERSION=${npmVersion} pack; then
built=1
break
fi
done
test $built -eq 1
";
installPhase = ''cp -r tools/wasm/dist $out'';
installPhase = "cp tools/wasm/linux.tgz $out";
};
}
);
Expand Down
2 changes: 2 additions & 0 deletions tools/wasm/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/.wrangler
/dist
/src/build
/npm-package
*.tgz
26 changes: 22 additions & 4 deletions tools/wasm/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,36 @@ endif

ESBUILD ?= esbuild
TSC ?= tsc
NPM ?= npm
PACKAGE = linux.tgz
PACKAGE_DIR = npm-package
PACKAGE_VERSION ?=

.PHONY: all clean _kernel
.PHONY: all clean pack _kernel
all: dist/index.js dist/index.d.ts

clean:
$(Q)rm -rf dist
$(Q)rm -rf dist $(PACKAGE_DIR) $(PACKAGE)

_kernel:
$(Q)$(MAKE) -C ../.. tools/wasm/src/build/vmlinux.wasm tools/wasm/src/build/sections.json tools/wasm/src/build/initramfs_data.cpio
$(Q)$(MAKE) -C ../.. tools/wasm/src/build/vmlinux.wasm tools/wasm/src/build/sections.json
$(Q)$(MAKE) -C ../.. tools/wasm/src/build/initramfs_data.cpio

dist/index.js: _kernel $(shell find src -type f)
$(Q)$(ESBUILD) --bundle src/index.ts --outdir=dist --format=esm --splitting --sourcemap --loader:.wasm=file --loader:.img=file --loader:.cpio=binary

dist/index.d.ts: $(shell find src -type f -name '*.ts')
dist/index.d.ts: _kernel $(shell find src -type f -name '*.ts')
$(Q)$(TSC)

pack: clean $(PACKAGE)

$(PACKAGE): all package.json
$(Q)rm -rf $(PACKAGE_DIR) $@
$(Q)mkdir -p $(PACKAGE_DIR)
$(Q)cp package.json $(PACKAGE_DIR)/
ifneq ($(PACKAGE_VERSION),)
$(Q)cd $(PACKAGE_DIR) && $(NPM) version --no-git-tag-version "$(PACKAGE_VERSION)" >/dev/null
endif
$(Q)cp -r dist $(PACKAGE_DIR)/
$(Q)cd $(PACKAGE_DIR) && npm_config_cache="$${TMPDIR:-..}/npm-cache" $(NPM) pack --pack-destination ..
$(Q)mv *.tgz $@
14 changes: 0 additions & 14 deletions tools/wasm/deno.lock

This file was deleted.

20 changes: 19 additions & 1 deletion tools/wasm/package.json
Original file line number Diff line number Diff line change
@@ -1 +1,19 @@
{ "type": "module" }
{
"name": "@tombl/linux",
"version": "0.0.0",
"type": "module",
"repository": {
"type": "git",
"url": "git+https://github.com/tombl/linux.git",
"directory": "tools/wasm"
},
"exports": {
".": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
}
},
"files": [
"dist"
]
}
17 changes: 0 additions & 17 deletions tools/wasm/public/404.html

This file was deleted.

5 changes: 0 additions & 5 deletions tools/wasm/public/_headers

This file was deleted.

1 change: 0 additions & 1 deletion tools/wasm/public/dist

This file was deleted.

Loading
Loading