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
21 changes: 15 additions & 6 deletions arch/wasm/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,27 @@ KBUILD_LDFLAGS += $(ldflags-y)

drivers-y += arch/wasm/drivers/

arch/wasm/vmlinux.wat: vmlinux.o
$(Q)wasm2wat $< --enable-all -o $@
quiet_cmd_wasm2wat = WAT $@
cmd_wasm2wat = wasm2wat $< --enable-all -o $@

arch/wasm/sections.json: arch/wasm/scripts/sections.pl arch/wasm/vmlinux.wat
$(Q)$(PERL) arch/wasm/scripts/sections.pl <arch/wasm/vmlinux.wat >$@
arch/wasm/vmlinux.wat: vmlinux.o FORCE
$(call if_changed,wasm2wat)

tools/wasm/vmlinux.wasm: vmlinux.o arch/wasm/sections.json usr/initramfs_inc_data
$(Q)$(OBJCOPY) \
quiet_cmd_wasm_sections = GEN $@
cmd_wasm_sections = $(PERL) arch/wasm/scripts/sections.pl <$< >$@

arch/wasm/sections.json: arch/wasm/vmlinux.wat arch/wasm/scripts/sections.pl FORCE
$(call if_changed,wasm_sections)

quiet_cmd_wasm_objcopy = OBJCOPY $@
cmd_wasm_objcopy = $(OBJCOPY) \
--add-section=.linux.sections=arch/wasm/sections.json \
--add-section=.linux.initramfs=usr/initramfs_inc_data \
$< $@

tools/wasm/vmlinux.wasm: vmlinux.o arch/wasm/sections.json FORCE
$(call if_changed,wasm_objcopy)

define archhelp
echo '* tools/wasm - WebAssembly host library'
endef
14 changes: 2 additions & 12 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,14 @@

wabt
typescript
nodejs
];

HOSTCC = "${llvm.clang}/bin/clang";
KBUILD_BUILD_TIMESTAMP = "1970-01-01 00:00:00 UTC";

enableParallelBuilding = true;
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 PACKAGE_VERSION=${npmVersion} pack; then
built=1
break
fi
done
test $built -eq 1
";
buildPhase = "make HOSTCC=$HOSTCC -j$NIX_BUILD_CORES -C tools/wasm PACKAGE_VERSION=${npmVersion} pack";
installPhase = "cp tools/wasm/linux.tgz $out";
};
}
Expand Down
22 changes: 11 additions & 11 deletions tools/wasm/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,20 @@ Q = @
endif

TSC ?= tsc
NPM ?= npm
PERL ?= perl
TAR ?= tar
PACKAGE = linux.tgz
PACKAGE_DIR = npm-package
PACKAGE_VERSION ?=
BUILD_ASSETS = vmlinux.wasm

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

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

_kernel:
vmlinux.wasm:
$(Q)$(MAKE) -C ../.. tools/wasm/vmlinux.wasm

dist/index.js dist/index.d.ts &: $(shell find src -type f)
Expand All @@ -28,12 +29,11 @@ pack: clean $(PACKAGE)

$(PACKAGE): all package.json
$(Q)rm -rf $(PACKAGE_DIR) $@
$(Q)mkdir -p $(PACKAGE_DIR)
$(Q)cp package.json $(PACKAGE_DIR)/
$(Q)cp vmlinux.wasm $(PACKAGE_DIR)/
$(Q)mkdir -p $(PACKAGE_DIR)/package
$(Q)cp package.json $(PACKAGE_DIR)/package/
$(Q)cp vmlinux.wasm $(PACKAGE_DIR)/package/
ifneq ($(PACKAGE_VERSION),)
$(Q)cd $(PACKAGE_DIR) && $(NPM) version --no-git-tag-version "$(PACKAGE_VERSION)" >/dev/null
$(Q)$(PERL) -0pi -e 's/"version":\s*"[^"]+"/"version": "$(PACKAGE_VERSION)"/' $(PACKAGE_DIR)/package/package.json
endif
$(Q)cp -r dist $(PACKAGE_DIR)/
$(Q)cd $(PACKAGE_DIR) && npm_config_cache="$${TMPDIR:-..}/npm-cache" $(NPM) pack --pack-destination ..
$(Q)mv *.tgz $@
$(Q)cp -r dist $(PACKAGE_DIR)/package/
$(Q)$(TAR) --sort=name --mtime='@0' --owner=0 --group=0 --numeric-owner -czf $@ -C $(PACKAGE_DIR) package
Loading