Makefile raw

   1  MOXIE    ?= $(CURDIR)/../moxie/moxie
   2  MOXIEJS  ?= $(CURDIR)/../moxie/moxiejs
   3  # An inherited MOXIEROOT is ignored on purpose: `?=` cannot tell an exported
   4  # stale root from an intended one, and a stale root silently compiles a
   5  # different tree's src/ and pkg/ (that is how `make build-app-wasm` failed
   6  # with "'err' shadows declaration in enclosing scope" from an old checkout,
   7  # while the same build with the repo root succeeds). Pass it on the command
   8  # line to build against another tree: make MOXIEROOT=/path/to/moxie ...
   9  ifeq ($(origin MOXIEROOT),environment)
  10  MOXIEROOT := $(CURDIR)/../moxie
  11  endif
  12  MOXIEROOT ?= $(CURDIR)/../moxie
  13  JSRUNTIME ?= $(CURDIR)/../moxie/jsruntime
  14  ISKRA    ?= $(HOME)/.local/bin/moxie-iskra
  15  # relay-proxy builds from source with the tree compiler. The earlier workaround
  16  # of using an installed moxie (its cached bitcode "avoided too much recursion
  17  # during _start()") was a symptom of a compiler bug: taking the address of a
  18  # frame local stored a stack pointer into the receiver's arena. Fixed in
  19  # _mxc_stage4 (markAddrEscaping mirrors the legacy compiler's Alloc.Heap), and
  20  # a fresh build now produces the same 430KB module the installed compiler did.
  21  MOXIE_RELAY_PROXY ?= $(MOXIE)
  22  
  23  # The relay is its OWN repo. This tree is the front end: nothing under web/
  24  # imports a relay package, and the relay's source lives in RELAY (../morly by
  25  # default). The suite still drives a relay binary - the app has to be served
  26  # from somewhere - so `relay-bin` builds it from that repo and the fixtures
  27  # take it through SMESH_RELAY_BIN.
  28  RELAY     ?= $(CURDIR)/../morly
  29  RELAY_BIN ?= $(CURDIR)/tmp/morly
  30  
  31  # Moxie closures do not capture: a closure receives what it needs through its
  32  # parameters, and the legacy compiler rejects a capturing one. stage4 enforces
  33  # the same rule by default. This app predates that enforcement and registers
  34  # hundreds of handlers that close over the enclosing frame (286 sites in
  35  # web/wasm/app alone), so every build here opts out explicitly. Porting them to
  36  # explicit parameters or to holder types with the callback as an interface is
  37  # tracked with the app, not the compiler; until it lands, the debt is declared
  38  # here rather than silently relying on stage4's old acceptance.
  39  CAPTURES ?= -allow-closure-captures
  40  
  41  # === Relay (a different repo) ===
  42  # Built only so the app has something to be served from; there is no relay
  43  # source here to build.
  44  relay-bin:
  45  	@mkdir -p $(dir $(RELAY_BIN))
  46  	cd $(RELAY) && MOXIEROOT=$(MOXIEROOT) $(MOXIE) build -o $(RELAY_BIN) .
  47  
  48  # === Frontend (WASM) ===
  49  build-app-wasm:
  50  	MOXIEROOT=$(MOXIEROOT) GOWORK=off $(MOXIE) build $(CAPTURES) -target wasm -o $(CURDIR)/web/static/app.wasm ./web/wasm/app/
  51  
  52  build-relay-proxy-wasm:
  53  	MOXIEROOT=$(MOXIEROOT) GOWORK=off $(MOXIE_RELAY_PROXY) build $(CAPTURES) -target wasm -o $(CURDIR)/web/static/relay-proxy.wasm ./web/wasm/relay-proxy/
  54  
  55  build-store-wasm:
  56  	MOXIEROOT=$(MOXIEROOT) GOWORK=off $(MOXIE) build $(CAPTURES) -target wasm -o $(CURDIR)/web/static/store.wasm ./web/wasm/store/
  57  
  58  build-verify-wasm:
  59  	MOXIEROOT=$(MOXIEROOT) GOWORK=off $(MOXIE) build $(CAPTURES) -target wasm -o $(CURDIR)/web/static/verify.wasm ./web/wasm/verify/
  60  
  61  build-profile-wasm:
  62  	MOXIEROOT=$(MOXIEROOT) GOWORK=off $(MOXIE) build $(CAPTURES) -target wasm -o $(CURDIR)/web/static/profile.wasm ./web/wasm/profile/
  63  
  64  build-feed-wasm:
  65  	MOXIEROOT=$(MOXIEROOT) GOWORK=off $(MOXIE) build $(CAPTURES) -target wasm -o $(CURDIR)/web/static/feed.wasm ./web/wasm/feed/
  66  
  67  build-mls-wasm:
  68  	MOXIEROOT=$(MOXIEROOT) GOWORK=off $(MOXIE) build $(CAPTURES) -target wasm -o $(CURDIR)/web/static/mls.wasm ./web/wasm/mls/
  69  
  70  build-notif-wasm:
  71  	MOXIEROOT=$(MOXIEROOT) GOWORK=off $(MOXIE) build $(CAPTURES) -target wasm -o $(CURDIR)/web/static/notif.wasm ./web/wasm/notif/
  72  
  73  build-sw:
  74  	MOXIEROOT=$(MOXIEROOT) GOWORK=off $(MOXIE) build $(CAPTURES) -target wasm -o $(CURDIR)/web/static/\$$sw/sw.wasm ./web/wasm/sw/
  75  
  76  # === Signer WASM (page-embedded worker) ===
  77  # The web app uses signer.wasm directly via signer-wasm-host.mjs.
  78  # No browser extension is required for normal operation.
  79  build-signer:
  80  	MOXIEROOT=$(MOXIEROOT) GOWORK=off $(MOXIE) build $(CAPTURES) -target wasm -o $(CURDIR)/web/static/signer.wasm ./web/wasm/signer/
  81  
  82  # Extension build (optional, not part of default build).
  83  build-ext-firefox: build-signer
  84  	cp $(CURDIR)/web/static/signer.wasm $(CURDIR)/web/ext/bg/signer.wasm
  85  	bash scripts/pack-ext.sh firefox
  86  	cp dist/smesh-signer-firefox.xpi web/static/smesh-signer.xpi
  87  
  88  build-ext: build-ext-firefox
  89  
  90  # === All ===
  91  # Direct messaging (MLS/Marmot) is parked again: the wasm worker panics in
  92  # Moxie's codec while generating its first KeyPackage (an invalid type
  93  # descriptor, kind=0), so its worker is not built or served and the app has no
  94  # /msg route. The mls code, host plumbing and worker all stay in the tree;
  95  # re-enable by restoring the sidebar entry, the router cases, the mlsWorkerTypes
  96  # branch and build-mls-wasm in `build`/`dev`.
  97  build: build-app-wasm build-relay-proxy-wasm build-store-wasm build-verify-wasm build-profile-wasm build-feed-wasm build-notif-wasm build-signer build-sw
  98  
  99  # === Test ===
 100  # Unit tests: every package under web/ carrying a *_test.mx, run by the
 101  # compiler's own test harness. The relay's own unit tests (and its coverage
 102  # run) live with the relay, in $(RELAY).
 103  test-unit:
 104  	@set -e ; for f in $$( find web -name '*_test.mx' | sort ) ; do \
 105  		d=$$(dirname $$f) ; \
 106  		echo "=== unit: $$d" ; \
 107  		MOXIEROOT=$(MOXIEROOT) $(MOXIE) test $(CAPTURES) ./$$d || exit 1 ; \
 108  	done
 109  
 110  test-signer: build-signer
 111  	node web/_test/signertest/run.mjs web/ext/bg/signer.wasm
 112  
 113  test: test-unit relay-bin test-signer
 114  	SMESH_RELAY_BIN=$(RELAY_BIN) ORLY_STATIC_DIR=$(CURDIR)/web/static \
 115  	 python3 -m pytest test/ -v --tb=short -x
 116  
 117  test-smoke: relay-bin
 118  	SMESH_RELAY_BIN=$(RELAY_BIN) ORLY_STATIC_DIR=$(CURDIR)/web/static \
 119  	 python3 -m pytest test/test_smoke.py -v --tb=short
 120  
 121  # Allocation instrumentation: the app wasm is rebuilt with -tags alloc_trace
 122  # and -print-allocs, which makes src/runtime publish the __moxie_* counters the
 123  # worker host reads in its __mem_query reply. The pattern is anchored to the
 124  # entry package: the compiler names a function by its package path, and the app
 125  # is the root package of its own module, so it is "main.<func>" - the same name
 126  # the legacy compiler reports.
 127  #
 128  # The instrumented module is scratch: the stock app.wasm is put back whether
 129  # the build or the tests fail, so this never leaves an instrumented artifact or
 130  # a stray side file in the tree. An instrumented build recompiles everything
 131  # serially (site ids are numbered in emit order), so it is slower than
 132  # build-app-wasm.
 133  APP_WASM := $(CURDIR)/web/static/app.wasm
 134  test-memory: relay-bin
 135  	@if [ -f "$(APP_WASM)" ]; then cp "$(APP_WASM)" "$(APP_WASM).stock"; fi ; \
 136  	 MOXIEROOT=$(MOXIEROOT) GOWORK=off $(MOXIE) build $(CAPTURES) -target wasm -tags alloc_trace \
 137  		-print-allocs '^main\.' -o $(APP_WASM) ./web/wasm/app/ ; \
 138  	 rc=$$? ; \
 139  	 rm -f "$(APP_WASM).alloc_sites.json" ; \
 140  	 if [ $$rc -eq 0 ]; then \
 141  		SMESH_RELAY_BIN=$(RELAY_BIN) ORLY_STATIC_DIR=$(CURDIR)/web/static \
 142  		 python3 -m pytest test/test_memory_profile.py -v --tb=short -m memory ; rc=$$? ; \
 143  	 fi ; \
 144  	 if [ -f "$(APP_WASM).stock" ]; then mv "$(APP_WASM).stock" "$(APP_WASM)"; fi ; \
 145  	 exit $$rc
 146  
 147  # === Dev (frontend only, relay already running) ===
 148  dev: build-app-wasm build-relay-proxy-wasm build-store-wasm build-verify-wasm build-profile-wasm build-feed-wasm build-notif-wasm build-sw
 149  
 150  .PHONY: relay-bin build-app-wasm build-relay-proxy-wasm build-store-wasm build-verify-wasm build-profile-wasm build-feed-wasm build-mls-wasm build-notif-wasm build-sw build-signer build-ext-firefox build-ext build dev test-signer test-unit test test-smoke test-memory
 151