github.com/tetratelabs/wazero@v1.7.3-0.20240513003603-48f702e154b5/Makefile (about)

     1  
     2  gofumpt       := mvdan.cc/gofumpt@v0.5.0
     3  gosimports    := github.com/rinchsan/gosimports/cmd/gosimports@v0.3.8
     4  golangci_lint := github.com/golangci/golangci-lint/cmd/golangci-lint@v1.55.2
     5  asmfmt        := github.com/klauspost/asmfmt/cmd/asmfmt@v1.3.2
     6  # sync this with netlify.toml!
     7  hugo          := github.com/gohugoio/hugo@v0.115.2
     8  
     9  # Make 3.81 doesn't support '**' globbing: Set explicitly instead of recursion.
    10  all_sources   := $(wildcard *.go */*.go */*/*.go */*/*/*.go */*/*/*.go */*/*/*/*.go)
    11  all_testdata  := $(wildcard testdata/* */testdata/* */*/testdata/* */*/testdata/*/* */*/*/testdata/*)
    12  all_testing   := $(wildcard internal/testing/* internal/testing/*/* internal/testing/*/*/*)
    13  all_examples  := $(wildcard examples/* examples/*/* examples/*/*/* */*/example/* */*/example/*/* */*/example/*/*/*)
    14  all_it        := $(wildcard internal/integration_test/* internal/integration_test/*/* internal/integration_test/*/*/*)
    15  # main_sources exclude any test or example related code
    16  main_sources  := $(wildcard $(filter-out %_test.go $(all_testdata) $(all_testing) $(all_examples) $(all_it), $(all_sources)))
    17  # main_packages collect the unique main source directories (sort will dedupe).
    18  # Paths need to all start with ./, so we do that manually vs foreach which strips it.
    19  main_packages := $(sort $(foreach f,$(dir $(main_sources)),$(if $(findstring ./,$(f)),./,./$(f))))
    20  
    21  go_test_options ?= -timeout 300s
    22  
    23  ensureCompilerFastest := -ldflags '-X github.com/tetratelabs/wazero/internal/integration_test/vs.ensureCompilerFastest=true'
    24  .PHONY: bench
    25  bench:
    26  	@go build ./internal/integration_test/bench/...
    27  	@# Don't use -test.benchmem as it isn't accurate when comparing against CGO libs
    28  	@for d in vs/time vs/wasmedge vs/wasmtime ; do \
    29  		cd ./internal/integration_test/$$d ; \
    30  		go test -bench=. . -tags='wasmedge' $(ensureCompilerFastest) ; \
    31  		cd - ;\
    32  	done
    33  
    34  bench_testdata_dir := internal/integration_test/bench/testdata
    35  .PHONY: build.bench
    36  build.bench:
    37  	@tinygo build -o $(bench_testdata_dir)/case.wasm -scheduler=none --no-debug -target=wasi $(bench_testdata_dir)/case.go
    38  
    39  .PHONY: test.examples
    40  test.examples:
    41  	@go test $(go_test_options) ./examples/... ./imports/assemblyscript/example/... ./imports/emscripten/... ./imports/wasi_snapshot_preview1/example/...
    42  
    43  .PHONY: build.examples.as
    44  build.examples.as:
    45  	@cd ./imports/assemblyscript/example/testdata && npm install && npm run build
    46  
    47  %.wasm: %.zig
    48  	@(cd $(@D); zig build -Doptimize=ReleaseSmall)
    49  	@mv $(@D)/zig-out/*/$(@F) $(@D)
    50  
    51  .PHONY: build.examples.zig
    52  build.examples.zig: examples/allocation/zig/testdata/greet.wasm imports/wasi_snapshot_preview1/example/testdata/zig/cat.wasm imports/wasi_snapshot_preview1/testdata/zig/wasi.wasm
    53  	@cd internal/testing/dwarftestdata/testdata/zig; zig build; mv zig-out/*/main.wasm ./ # Need DWARF custom sections.
    54  
    55  tinygo_sources := examples/basic/testdata/add.go examples/allocation/tinygo/testdata/greet.go examples/cli/testdata/cli.go imports/wasi_snapshot_preview1/example/testdata/tinygo/cat.go imports/wasi_snapshot_preview1/testdata/tinygo/wasi.go cmd/wazero/testdata/cat/cat.go
    56  .PHONY: build.examples.tinygo
    57  build.examples.tinygo: $(tinygo_sources)
    58  	@for f in $^; do \
    59  	    tinygo build -o $$(echo $$f | sed -e 's/\.go/\.wasm/') -scheduler=none --no-debug --target=wasi $$f; \
    60  	done
    61  	@mv cmd/wazero/testdata/cat/cat.wasm cmd/wazero/testdata/cat/cat-tinygo.wasm
    62  
    63  # We use zig to build C as it is easy to install and embeds a copy of zig-cc.
    64  # Note: Don't use "-Oz" as that breaks our wasi sock example.
    65  c_sources := imports/wasi_snapshot_preview1/example/testdata/zig-cc/cat.c imports/wasi_snapshot_preview1/testdata/zig-cc/wasi.c internal/testing/dwarftestdata/testdata/zig-cc/main.c
    66  .PHONY: build.examples.zig-cc
    67  build.examples.zig-cc: $(c_sources)
    68  	@for f in $^; do \
    69  	    zig cc --target=wasm32-wasi -o $$(echo $$f | sed -e 's/\.c/\.wasm/') $$f; \
    70  	done
    71  
    72  # Here are the emcc args we use:
    73  #
    74  # * `-Oz` - most optimization for code size.
    75  # * `--profiling` - adds the name section.
    76  # * `-s STANDALONE_WASM` - ensures wasm is built for a non-js runtime.
    77  # * `-s EXPORTED_FUNCTIONS=_malloc,_free` - export allocation functions so that
    78  #   they can be used externally as "malloc" and "free".
    79  # * `-s WARN_ON_UNDEFINED_SYMBOLS=0` - imports not defined in JavaScript error
    80  #   otherwise. See https://github.com/emscripten-core/emscripten/issues/13641
    81  # * `-s TOTAL_STACK=8KB -s TOTAL_MEMORY=64KB` - reduce memory default from 16MB
    82  #   to one page (64KB). To do this, we have to reduce the stack size.
    83  # * `-s ALLOW_MEMORY_GROWTH` - allows "memory.grow" instructions to succeed, but
    84  #   requires a function import "emscripten_notify_memory_growth".
    85  emscripten_sources := $(wildcard imports/emscripten/testdata/*.cc)
    86  .PHONY: build.examples.emscripten
    87  build.examples.emscripten: $(emscripten_sources)
    88  	@for f in $^; do \
    89  		em++ -Oz --profiling \
    90  		-s STANDALONE_WASM \
    91  		-s EXPORTED_FUNCTIONS=_malloc,_free \
    92  		-s WARN_ON_UNDEFINED_SYMBOLS=0 \
    93  		-s TOTAL_STACK=8KB -s TOTAL_MEMORY=64KB \
    94  		-s ALLOW_MEMORY_GROWTH \
    95  		--std=c++17 -o $$(echo $$f | sed -e 's/\.cc/\.wasm/') $$f; \
    96  	done
    97  
    98  %/greet.wasm : cargo_target := wasm32-unknown-unknown
    99  %/cat.wasm : cargo_target := wasm32-wasi
   100  %/wasi.wasm : cargo_target := wasm32-wasi
   101  
   102  .PHONY: build.examples.rust
   103  build.examples.rust: examples/allocation/rust/testdata/greet.wasm imports/wasi_snapshot_preview1/example/testdata/cargo-wasi/cat.wasm imports/wasi_snapshot_preview1/testdata/cargo-wasi/wasi.wasm internal/testing/dwarftestdata/testdata/rust/main.wasm.xz
   104  
   105  # Normally, we build release because it is smaller. Testing dwarf requires the debug build.
   106  internal/testing/dwarftestdata/testdata/rust/main.wasm.xz:
   107  	cd $(@D) && cargo wasi build
   108  	mv $(@D)/target/wasm32-wasi/debug/main.wasm $(@D)
   109  	cd $(@D) && xz -k -f ./main.wasm # Rust's DWARF section is huge, so compress it.
   110  
   111  # Builds rust using cargo normally, or cargo-wasi.
   112  %.wasm: %.rs
   113  	@(cd $(@D); cargo $(if $(findstring wasi,$(cargo_target)),wasi build,build --target $(cargo_target)) --release)
   114  	@mv $(@D)/target/$(cargo_target)/release/$(@F) $(@D)
   115  
   116  spectest_base_dir := internal/integration_test/spectest
   117  spectest_v1_dir := $(spectest_base_dir)/v1
   118  spectest_v1_testdata_dir := $(spectest_v1_dir)/testdata
   119  spec_version_v1 := wg-1.0
   120  spectest_v2_dir := $(spectest_base_dir)/v2
   121  spectest_v2_testdata_dir := $(spectest_v2_dir)/testdata
   122  # Latest draft state as of March 12, 2024.
   123  spec_version_v2 := 1c5e5d178bd75c79b7a12881c529098beaee2a05
   124  spectest_threads_dir := $(spectest_base_dir)/threads
   125  spectest_threads_testdata_dir := $(spectest_threads_dir)/testdata
   126  # From https://github.com/WebAssembly/threads/tree/upstream-rebuild which has not been merged to main yet.
   127  # It will likely be renamed to main in the future - https://github.com/WebAssembly/threads/issues/216.
   128  spec_version_threads := 3635ca51a17e57e106988846c5b0e0cc48ac04fc
   129  
   130  .PHONY: build.spectest
   131  build.spectest:
   132  	@$(MAKE) build.spectest.v1
   133  	@$(MAKE) build.spectest.v2
   134  
   135  .PHONY: build.spectest.v1
   136  build.spectest.v1: # Note: wabt by default uses >1.0 features, so wast2json flags might drift as they include more. See WebAssembly/wabt#1878
   137  	@rm -rf $(spectest_v1_testdata_dir)
   138  	@mkdir -p $(spectest_v1_testdata_dir)
   139  	@cd $(spectest_v1_testdata_dir) \
   140  		&& curl -sSL 'https://api.github.com/repos/WebAssembly/spec/contents/test/core?ref=$(spec_version_v1)' | jq -r '.[]| .download_url' | grep -E ".wast" | xargs -Iurl curl -sJL url -O
   141  	@cd $(spectest_v1_testdata_dir) && for f in `find . -name '*.wast'`; do \
   142  		perl -pi -e 's/\(assert_return_canonical_nan\s(\(invoke\s"f32.demote_f64"\s\((f[0-9]{2})\.const\s[a-z0-9.+:-]+\)\))\)/\(assert_return $$1 \(f32.const nan:canonical\)\)/g' $$f; \
   143  		perl -pi -e 's/\(assert_return_arithmetic_nan\s(\(invoke\s"f32.demote_f64"\s\((f[0-9]{2})\.const\s[a-z0-9.+:-]+\)\))\)/\(assert_return $$1 \(f32.const nan:arithmetic\)\)/g' $$f; \
   144  		perl -pi -e 's/\(assert_return_canonical_nan\s(\(invoke\s"f64\.promote_f32"\s\((f[0-9]{2})\.const\s[a-z0-9.+:-]+\)\))\)/\(assert_return $$1 \(f64.const nan:canonical\)\)/g' $$f; \
   145  		perl -pi -e 's/\(assert_return_arithmetic_nan\s(\(invoke\s"f64\.promote_f32"\s\((f[0-9]{2})\.const\s[a-z0-9.+:-]+\)\))\)/\(assert_return $$1 \(f64.const nan:arithmetic\)\)/g' $$f; \
   146  		perl -pi -e 's/\(assert_return_canonical_nan\s(\(invoke\s"[a-z._0-9]+"\s\((f[0-9]{2})\.const\s[a-z0-9.+:-]+\)\))\)/\(assert_return $$1 \($$2.const nan:canonical\)\)/g' $$f; \
   147  		perl -pi -e 's/\(assert_return_arithmetic_nan\s(\(invoke\s"[a-z._0-9]+"\s\((f[0-9]{2})\.const\s[a-z0-9.+:-]+\)\))\)/\(assert_return $$1 \($$2.const nan:arithmetic\)\)/g' $$f; \
   148  		perl -pi -e 's/\(assert_return_canonical_nan\s(\(invoke\s"[a-z._0-9]+"\s\((f[0-9]{2})\.const\s[a-z0-9.+:-]+\)\s\([a-z0-9.\s+-:]+\)\))\)/\(assert_return $$1 \($$2.const nan:canonical\)\)/g' $$f; \
   149  		perl -pi -e 's/\(assert_return_arithmetic_nan\s(\(invoke\s"[a-z._0-9]+"\s\((f[0-9]{2})\.const\s[a-z0-9.+:-]+\)\s\([a-z0-9.\s+-:]+\)\))\)/\(assert_return $$1 \($$2.const nan:arithmetic\)\)/g' $$f; \
   150  		perl -pi -e 's/\(assert_return_canonical_nan\s(\(invoke\s"[a-z._0-9]+"\s\((f[0-9]{2})\.const\s[a-z0-9.+:-]+\)\))\)/\(assert_return $$1 \($$2.const nan:canonical\)\)/g' $$f; \
   151  		perl -pi -e 's/\(assert_return_arithmetic_nan\s(\(invoke\s"[a-z._0-9]+"\s\((f[0-9]{2})\.const\s[a-z0-9.+:-]+\)\))\)/\(assert_return $$1 \($$2.const nan:arithmetic\)\)/g' $$f; \
   152  		wast2json \
   153  			--disable-saturating-float-to-int \
   154  			--disable-sign-extension \
   155  			--disable-simd \
   156  			--disable-multi-value \
   157  			--disable-bulk-memory \
   158  			--disable-reference-types \
   159  			--debug-names $$f; \
   160  	done
   161  
   162  .PHONY: build.spectest.v2
   163  build.spectest.v2: # Note: SIMD cases are placed in the "simd" subdirectory.
   164  	@mkdir -p $(spectest_v2_testdata_dir)
   165  	@cd $(spectest_v2_testdata_dir) \
   166  		&& curl -sSL 'https://api.github.com/repos/WebAssembly/spec/contents/test/core?ref=$(spec_version_v2)' | jq -r '.[]| .download_url' | grep -E ".wast" | xargs -Iurl curl -sJL url -O
   167  	@cd $(spectest_v2_testdata_dir) \
   168  		&& curl -sSL 'https://api.github.com/repos/WebAssembly/spec/contents/test/core/simd?ref=$(spec_version_v2)' | jq -r '.[]| .download_url' | grep -E ".wast" | xargs -Iurl curl -sJL url -O
   169  	@cd $(spectest_v2_testdata_dir) && for f in `find . -name '*.wast'`; do \
   170  		wast2json --debug-names --no-check $$f || true; \
   171  	done # Ignore the error here as some tests (e.g. comments.wast right now) are not supported by wast2json yet.
   172  
   173  # Note: We currently cannot build the "threads" subdirectory that spawns threads due to missing support in wast2json.
   174  # https://github.com/WebAssembly/wabt/issues/2348#issuecomment-1878003959
   175  .PHONY: build.spectest.threads
   176  build.spectest.threads:
   177  	@mkdir -p $(spectest_threads_testdata_dir)
   178  	@cd $(spectest_threads_testdata_dir) \
   179  		&& curl -sSL 'https://api.github.com/repos/WebAssembly/threads/contents/test/core?ref=$(spec_version_threads)' | jq -r '.[]| .download_url' | grep -E "atomic.wast" | xargs -Iurl curl -sJL url -O
   180  	@cd $(spectest_threads_testdata_dir) && for f in `find . -name '*.wast'`; do \
   181  		wast2json --enable-threads --debug-names $$f; \
   182  	done
   183  
   184  .PHONY: test
   185  test:
   186  	@go test $(go_test_options) $$(go list ./... | grep -vE '$(spectest_v1_dir)|$(spectest_v2_dir)')
   187  	@cd internal/version/testdata && go test $(go_test_options) ./...
   188  	@cd internal/integration_test/fuzz/wazerolib && CGO_ENABLED=0 WASM_BINARY_PATH=testdata/test.wasm go test ./...
   189  
   190  .PHONY: coverage
   191  # replace spaces with commas
   192  coverpkg = $(shell echo $(main_packages) | tr ' ' ',')
   193  coverage: ## Generate test coverage
   194  	@go test -coverprofile=coverage.txt -covermode=atomic --coverpkg=$(coverpkg) $(main_packages)
   195  	@go tool cover -func coverage.txt
   196  
   197  .PHONY: spectest
   198  spectest:
   199  	@$(MAKE) spectest.v1
   200  	@$(MAKE) spectest.v2
   201  
   202  spectest.v1:
   203  	@go test $(go_test_options) $$(go list ./... | grep $(spectest_v1_dir))
   204  
   205  spectest.v2:
   206  	@go test $(go_test_options) $$(go list ./... | grep $(spectest_v2_dir))
   207  
   208  golangci_lint_path := $(shell go env GOPATH)/bin/golangci-lint
   209  
   210  $(golangci_lint_path):
   211  	@go install $(golangci_lint)
   212  
   213  golangci_lint_goarch ?= $(shell go env GOARCH)
   214  
   215  .PHONY: lint
   216  lint: $(golangci_lint_path)
   217  	@GOARCH=$(golangci_lint_goarch) CGO_ENABLED=0 $(golangci_lint_path) run --timeout 5m
   218  
   219  .PHONY: format
   220  format:
   221  	@go run $(gofumpt) -l -w .
   222  	@go run $(gosimports) -local github.com/tetratelabs/ -w $(shell find . -name '*.go' -type f)
   223  	@go run $(asmfmt) -w $(shell find . -name '*.s' -type f)
   224  
   225  .PHONY: check  # Pre-flight check for pull requests
   226  check:
   227  # The following checks help ensure our platform-specific code used for system
   228  # calls safely falls back on a platform unsupported by the compiler engine.
   229  # This makes sure the intepreter can be used. Most often the package that can
   230  # drift here is "platform" or "sysfs":
   231  #
   232  # Ensure we build on plan9. See #1578
   233  	@GOARCH=amd64 GOOS=plan9 go build ./...
   234  # Ensure we build on gojs. See #1526.
   235  	@GOARCH=wasm GOOS=js go build ./...
   236  # Ensure we build on wasip1. See #1526.
   237  	@GOARCH=wasm GOOS=wasip1 go build ./...
   238  # Ensure we build on aix. See #1723
   239  	@GOARCH=ppc64 GOOS=aix go build ./...
   240  # Ensure we build on windows:
   241  	@GOARCH=amd64 GOOS=windows go build ./...
   242  # Ensure we build on an arbitrary operating system:
   243  	@GOARCH=amd64 GOOS=dragonfly go build ./...
   244  # Ensure we build on solaris/illumos:
   245  	@GOARCH=amd64 GOOS=illumos go build ./...
   246  	@GOARCH=amd64 GOOS=solaris go build ./...
   247  # Ensure we build on linux arm for Dapr:
   248  #	gh release view -R dapr/dapr --json assets --jq 'first(.assets[] | select(.name = "daprd_linux_arm.tar.gz") | {url, downloadCount})'
   249  	@GOARCH=arm GOOS=linux go build ./...
   250  # Ensure we build on linux 386 for Trivy:
   251  #	gh release view -R aquasecurity/trivy --json assets --jq 'first(.assets[] | select(.name| test("Linux-32bit.*tar.gz")) | {url, downloadCount})'
   252  	@GOARCH=386 GOOS=linux go build ./...
   253  # Ensure we build on FreeBSD amd64 for Trivy:
   254  #	gh release view -R aquasecurity/trivy --json assets --jq 'first(.assets[] | select(.name| test("FreeBSD-64bit.*tar.gz")) | {url, downloadCount})'
   255  	@GOARCH=amd64 GOOS=freebsd go build ./...
   256  	@$(MAKE) lint golangci_lint_goarch=arm64
   257  	@$(MAKE) lint golangci_lint_goarch=amd64
   258  	@$(MAKE) format
   259  	@go mod tidy
   260  	@if [ ! -z "`git status -s`" ]; then \
   261  		echo "The following differences will fail CI until committed:"; \
   262  		git diff --exit-code; \
   263  	fi
   264  
   265  .PHONY: site
   266  site: ## Serve website content
   267  	@git submodule update --init
   268  	@cd site && go run $(hugo) server --minify --disableFastRender --baseURL localhost:1313 --cleanDestinationDir -D
   269  
   270  .PHONY: clean
   271  clean: ## Ensure a clean build
   272  	@rm -rf dist build coverage.txt
   273  	@go clean -testcache
   274  
   275  fuzz_default_flags := --no-trace-compares --sanitizer=none -- -rss_limit_mb=8192
   276  
   277  fuzz_timeout_seconds ?= 10
   278  .PHONY: fuzz
   279  fuzz:
   280  	@cd internal/integration_test/fuzz && cargo test
   281  	@cd internal/integration_test/fuzz && cargo fuzz run logging_no_diff $(fuzz_default_flags) -max_total_time=$(fuzz_timeout_seconds)
   282  	@cd internal/integration_test/fuzz && cargo fuzz run no_diff $(fuzz_default_flags) -max_total_time=$(fuzz_timeout_seconds)
   283  	@cd internal/integration_test/fuzz && cargo fuzz run memory_no_diff $(fuzz_default_flags) -max_total_time=$(fuzz_timeout_seconds)
   284  	@cd internal/integration_test/fuzz && cargo fuzz run validation $(fuzz_default_flags) -max_total_time=$(fuzz_timeout_seconds)
   285  
   286  libsodium:
   287  	cd ./internal/integration_test/libsodium/testdata && \
   288  		curl -s "https://api.github.com/repos/jedisct1/webassembly-benchmarks/contents/2022-12/wasm?ref=7e86d68e99e60130899fbe3b3ab6e9dce9187a7c" \
   289  		| jq -r '.[] | .download_url' | xargs -n 1 curl -LO
   290  
   291  #### CLI release related ####
   292  
   293  VERSION ?= dev
   294  # Default to a dummy version 0.0.1.1, which is always lower than a real release.
   295  # Legal version values should look like 'x.x.x.x' where x is an integer from 0 to 65534.
   296  # https://learn.microsoft.com/en-us/windows/win32/msi/productversion?redirectedfrom=MSDN
   297  # https://stackoverflow.com/questions/9312221/msi-version-numbers
   298  MSI_VERSION ?= 0.0.1.1
   299  non_windows_platforms := darwin_amd64 darwin_arm64 linux_amd64 linux_arm64
   300  non_windows_archives  := $(non_windows_platforms:%=dist/wazero_$(VERSION)_%.tar.gz)
   301  windows_platforms     := windows_amd64 # TODO: add arm64 windows once we start testing on it.
   302  windows_archives      := $(windows_platforms:%=dist/wazero_$(VERSION)_%.zip) $(windows_platforms:%=dist/wazero_$(VERSION)_%.msi)
   303  checksum_txt          := dist/wazero_$(VERSION)_checksums.txt
   304  
   305  # define macros for multi-platform builds. these parse the filename being built
   306  go-arch = $(if $(findstring amd64,$1),amd64,arm64)
   307  go-os   = $(if $(findstring .exe,$1),windows,$(if $(findstring linux,$1),linux,darwin))
   308  # msi-arch is a macro so we can detect it based on the file naming convention
   309  msi-arch     = $(if $(findstring amd64,$1),x64,arm64)
   310  
   311  build/wazero_%/wazero:
   312  	$(call go-build,$@,$<)
   313  
   314  build/wazero_%/wazero.exe:
   315  	$(call go-build,$@,$<)
   316  
   317  dist/wazero_$(VERSION)_%.tar.gz: build/wazero_%/wazero
   318  	@echo tar.gz "tarring $@"
   319  	@mkdir -p $(@D)
   320  # On Windows, we pass the special flag `--mode='+rx' to ensure that we set the executable flag.
   321  # This is only supported by GNU Tar, so we set it conditionally.
   322  	@tar -C $(<D) -cpzf $@ $(if $(findstring Windows_NT,$(OS)),--mode='+rx',) $(<F)
   323  	@echo tar.gz "ok"
   324  
   325  define go-build
   326  	@echo "building $1"
   327  	@# $(go:go=) removes the trailing 'go', so we can insert cross-build variables
   328  	@$(go:go=) CGO_ENABLED=0 GOOS=$(call go-os,$1) GOARCH=$(call go-arch,$1) go build \
   329  		-ldflags "-s -w -X github.com/tetratelabs/wazero/internal/version.version=$(VERSION)" \
   330  		-o $1 $2 ./cmd/wazero
   331  	@echo build "ok"
   332  endef
   333  
   334  # this makes a marker file ending in .signed to avoid repeatedly calling codesign
   335  %.signed: %
   336  	$(call codesign,$<)
   337  	@touch $@
   338  
   339  # This requires osslsigncode package (apt or brew) or latest windows release from mtrojnar/osslsigncode
   340  #
   341  # Default is self-signed while production should be a Digicert signing key
   342  #
   343  # Ex.
   344  # ```bash
   345  # keytool -genkey -alias wazero -storetype PKCS12 -keyalg RSA -keysize 2048 -storepass wazero-bunch \
   346  # -keystore wazero.p12 -dname "O=wazero,CN=wazero.io" -validity 3650
   347  # ```
   348  WINDOWS_CODESIGN_P12      ?= packaging/msi/wazero.p12
   349  WINDOWS_CODESIGN_PASSWORD ?= wazero-bunch
   350  define codesign
   351  	@printf "$(ansi_format_dark)" codesign "signing $1"
   352  	@osslsigncode sign -h sha256 -pkcs12 ${WINDOWS_CODESIGN_P12} -pass "${WINDOWS_CODESIGN_PASSWORD}" \
   353  	-n "wazero is the zero dependency WebAssembly runtime for Go developers" -i https://wazero.io -t http://timestamp.digicert.com \
   354  	$(if $(findstring msi,$(1)),-add-msi-dse) -in $1 -out $1-signed
   355  	@mv $1-signed $1
   356  	@printf "$(ansi_format_bright)" codesign "ok"
   357  endef
   358  
   359  # This task is only supported on Windows, where we use candle.exe (compile wxs to wixobj) and light.exe (link to msi)
   360  dist/wazero_$(VERSION)_%.msi: build/wazero_%/wazero.exe.signed
   361  ifeq ($(OS),Windows_NT)
   362  	@echo msi "building $@"
   363  	@mkdir -p $(@D)
   364  	@candle -nologo -arch $(call msi-arch,$@) -dVersion=$(MSI_VERSION) -dBin=$(<:.signed=) -o build/wazero.wixobj packaging/msi/wazero.wxs
   365  	@light -nologo -o $@ build/wazero.wixobj -spdb
   366  	$(call codesign,$@)
   367  	@echo msi "ok"
   368  endif
   369  
   370  dist/wazero_$(VERSION)_%.zip: build/wazero_%/wazero.exe.signed
   371  	@echo zip "zipping $@"
   372  	@mkdir -p $(@D)
   373  	@zip -qj $@ $(<:.signed=)
   374  	@echo zip "ok"
   375  
   376  # Darwin doesn't have sha256sum. See https://github.com/actions/virtual-environments/issues/90
   377  sha256sum := $(if $(findstring darwin,$(shell go env GOOS)),shasum -a 256,sha256sum)
   378  $(checksum_txt):
   379  	@cd $(@D); touch $(@F); $(sha256sum) * >> $(@F)
   380  
   381  dist: $(non_windows_archives) $(if $(findstring Windows_NT,$(OS)),$(windows_archives),) $(checksum_txt)