|
|
hai 3 semanas | |
|---|---|---|
| .. | ||
| src | hai 3 semanas | |
| wasm-apps | hai 1 mes | |
| .gitignore | hai 1 mes | |
| CMakeLists.txt | hai 1 mes | |
| README.md | hai 1 mes | |
| build.sh | hai 1 mes | |
| run.sh | hai 1 mes | |
This sample demonstrates how to:
.s fileWAMR_BUILD_LOAD_CUSTOM_SECTION=1demo custom sectionThe Wasm application is built from:
wasm-apps/custom_section.cwasm-apps/custom_section_payload.swasm-apps/custom_section_payload.binThe assembler file emits a section named .custom_section.demo, which becomes a Wasm custom section named demo in the final .wasm file.
The payload in this sample is treated as read-only metadata. Putting it in a custom section lets the embedder access the bytes directly from the loaded module through wasm_runtime_get_custom_section, instead of copying the data into Wasm linear memory per instance.
That matters when the data is large or rarely changed:
This pattern is useful for embedded assets, lookup tables, model metadata, certificates, and other static blobs that the host wants to consume without treating them as mutable Wasm heap data.
Execute the build.sh script. The host executable and the Wasm app are generated in out.
./build.sh
Build the AoT variant only when needed by passing --aot. This preserves the demo custom section in the generated AoT file by calling wamrc --emit-custom-sections=demo.
./build.sh --aot
Enter the output directory and run the Wasm sample directly:
cd ./out/
./custom_section -f wasm-apps/custom_section.wasm
Or run the helper script from samples/custom_section:
./run.sh
To run the AoT artifact instead, pass --aot to the helper script:
./run.sh --aot