WebAssembly, WASI, Component Model 코드를 로컬에서 실행, 사전 컴파일, 검사할 수 있는 Wasmtime CLI.
wasmtime 는 Bytecode Alliance의 WebAssembly runtime CLI이다.run 으로 처리되어 입력한 .wasm 또는 .wat 파일을 실행한다.앞 에 배치해야 하며, 파일 뒤 인수는 게스트 프로그램의 CLI 인수로 전달된다..cwasm 분석과 같은 작업을 한 도구에서 처리할 수 있다.wasmtime [OPTIONS] <WASM-OR-SUBCOMMAND> [ARGS...] wasmtime run [OPTIONS] module.wasm [ARGS...] wasmtime serve [OPTIONS] component.wasm wasmtime compile [OPTIONS] module.wasm
wasmtime [OPTIONS] FILE [ARGS…]wasmtime run [OPTIONS] MODULE.wasm [ARGS…]wasmtime serve [OPTIONS] COMPONENT.wasmwasmtime compile [OPTIONS] MODULE.wasmwasmtime objdump [OPTIONS] MODULE.cwasmwasmtime module.wasm 처럼 실행하면 wasmtime run module.wasm 과 동일하게 동작한다..wasm 바이너리뿐 아니라 .wat 텍스트 형식도 직접 실행할 수 있다.wasmtime help: 전체 도움말 또는 특정 subcommand 도움말 출력wasmtime run: WebAssembly module 또는 component 실행wasmtime serve: wasi:http/proxy world 기준으로 HTTP component 실행wasmtime wast: WebAssembly spec test 형식인 .wast 실행wasmtime config: 로컬 설정과 cache 설정 파일 생성 및 편집wasmtime completion: shell completion 스크립트 생성wasmtime compile: module을 Ahead-Of-Time compile 해서 .cwasm 생성wasmtime settings: host target 기준 Cranelift 설정 확인wasmtime explore: wasm을 compile하고 HTML 탐색 결과 생성wasmtime objdump: .cwasm 내부 native instruction을 터미널에서 확인–invoke EXPORT: 기본 entrypoint 대신 특정 export 실행–dir PATH: guest에 디렉터리 접근 권한 부여. 반드시 wasm 파일 앞에 둔다–env KEY=VALUE: guest에 환경 변수 전달# 기본 run 동작 wasmtime hello.wasm # 텍스트 형식(.wat)도 직접 실행 wasmtime hello.wat # guest 프로그램 인수 전달 wasmtime app.wasm --mode prod --port 8080
wasmtime foo.wasm –dir . 는 –dir . 을 Wasmtime이 아니라 guest 프로그램 인수로 넘긴다.
# 현재 디렉터리를 guest에 mount wasmtime --dir . app.wasm # 환경 변수 전달 wasmtime --env APP_ENV=dev app.wasm
# core wasm module의 특정 export 실행 wasmtime run --invoke initialize init.wasm # 정수 인수를 받는 export 실행 wasmtime run --invoke add add.wasm 1 2 # component export 실행 시 WAVE 문법 사용 wasmtime run --invoke 'initialize("hello")' component.wasm
–invoke 를 통한 일부 CLI 인수 구문이 아직 unstable 하며 향후 바뀔 수 있다고 안내한다.
# wasi:http/proxy world 기반 component 실행 wasmtime serve proxy.wasm # listen address 지정 wasmtime serve --addr=0.0.0.0:8081 proxy.wasm
# AOT compile wasmtime compile app.wasm # 생성된 .cwasm 실행 wasmtime app.cwasm # shell completion 생성 wasmtime completion zsh # compiled wasm의 native code 확인 wasmtime objdump app.cwasm
wasmtime config new 으로 로컬 설정 파일을 생성할 수 있다.wasmtime settings 로 host target에 대해 Cranelift가 추론한 설정을 확인할 수 있다.serve 사용 시 target component가 wasi:http/proxy world를 따르는지 확인한다..cwasm 이 다른 환경에서 실행되지 않으면 AOT compile 시점의 target 환경과 실행 호스트 호환성을 점검한다.serve subcommand는 Wasmtime 18.0.0 이후의 WASI HTTP API를 전제로 한다..cwasm 파일은 target 환경 호환성이 필요하므로, 모든 호스트에서 이식적으로 실행되는 것은 아니다.로컬 환경에 wasmtime binary가 없어 실제 ''wasmtime --help'' 출력은 수집하지 못했다. 참고: * https://wasmtime.dev/ * https://docs.wasmtime.dev/cli-options.html
+