github.com/filecoin-project/bacalhau@v0.3.23-0.20230228154132-45c989550ace/testdata/wasm/Makefile (about)

     1  ifeq ($(shell which wasm-gc),)
     2  $(info "No wasm-gc. Install it with cargo install wasm-gc")
     3  endif
     4  
     5  WASM_DIRS := $(shell find . -type d -depth 1)
     6  WASM_FILES := $(patsubst ./%,%/main.wasm,${WASM_DIRS})
     7  EMBED_FILES := $(patsubst ./%,%/main.go,${WASM_DIRS})
     8  
     9  %.wat: %.wasm
    10  	wasm2wat $^ > $@
    11  
    12  %.wasm:
    13  	pushd $(dir $@) && \
    14  	cargo build --target wasm32-wasi --release && \
    15  	popd && \
    16  	cp $(dir $@)/target/wasm32-wasi/release/*.wasm $@ && \
    17  	wasm-gc $@
    18  
    19  %.go: %.wasm
    20  	echo "// Generated by Makefile - DO NOT EDIT." > $@; \
    21  	echo "package $$(dirname $@)\n" >> $@; \
    22  	echo "import \"embed\"" >> $@; \
    23  	echo "import \"io/fs\"\n" >> $@; \
    24  	echo "//go:embed $$(basename $^)" >> $@; \
    25  	echo "var file embed.FS" >> $@
    26  	echo "func Program() (b []byte) {" >> $@; \
    27  	echo "	b, err := fs.ReadFile(file, \"$$(basename $^)\")" >> $@; \
    28  	echo "	if err != nil {" >> $@; \
    29  	echo "		panic(err)" >> $@; \
    30  	echo "	}" >> $@; \
    31  	echo "	return" >> $@; \
    32  	echo "}" >> $@;
    33  
    34  %.csv: %.sparql
    35  	curl -G https://query.wikidata.org/sparql \
    36  		--data-urlencode "query=$$(cat $^)" \
    37  		-H "Accept: text/csv" -o $@
    38  
    39  .PHONY: all
    40  all: ${WASM_FILES} ${EMBED_FILES}
    41  
    42  .PHONY: clean
    43  clean:
    44  	$(RM) ${EMBED_FILES}