Skip to content

Commit 6659a31

Browse files
authored
add a sample to use cmake package (#4291)
- add a sample to use cmake package
1 parent b7474b3 commit 6659a31

File tree

5 files changed

+65
-0
lines changed

5 files changed

+65
-0
lines changed

.github/workflows/compilation_on_android_ubuntu.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,11 @@ jobs:
437437
ctest --test-dir build --output-on-failure
438438
working-directory: samples/wasm-c-api
439439

440+
- name: Build Sample [printversion]
441+
run: |
442+
./test.sh
443+
working-directory: samples/printversion
444+
440445
build_samples_others:
441446
needs:
442447
[

.github/workflows/compilation_on_macos.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,11 @@ jobs:
282282
ctest --test-dir build --output-on-failure
283283
working-directory: samples/wasm-c-api
284284

285+
- name: Build Sample [printversion]
286+
run: |
287+
./test.sh
288+
working-directory: samples/printversion
289+
285290
build_samples_others:
286291
needs: [build_iwasm, build_wamrc, build_llvm_libraries_on_intel_macos, build_llvm_libraries_on_arm_macos]
287292
runs-on: ${{ matrix.os }}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Copyright (C) 2025 Midokura Japan KK. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3+
4+
cmake_minimum_required(VERSION 3.16)
5+
6+
project(printversion LANGUAGES C)
7+
8+
add_executable(printversion printversion.c)
9+
find_package(iwasm REQUIRED)
10+
target_link_libraries(printversion iwasm::vmlib)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright (C) 2025 Midokura Japan KK. All rights reserved.
3+
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4+
*/
5+
6+
#include <inttypes.h>
7+
#include <stdint.h>
8+
#include <stdio.h>
9+
10+
#include <wasm_export.h>
11+
12+
int
13+
main(int argc, char **argv)
14+
{
15+
uint32_t major;
16+
uint32_t minor;
17+
uint32_t patch;
18+
wasm_runtime_get_version(&major, &minor, &patch);
19+
printf("wasm-micro-runtime %" PRIu32 ".%" PRIu32 ".%" PRIu32 "\n", major,
20+
minor, patch);
21+
}

samples/printversion/test.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#! /bin/sh
2+
3+
# Copyright (C) 2025 Midokura Japan KK. All rights reserved.
4+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5+
6+
set -e
7+
8+
DIST=$(mktemp -d)
9+
10+
# WAMR_BUILD_SIMD=0 to avoid fetching simde, which is
11+
# not relevant to this particular test.
12+
cmake -B build-wamr \
13+
-D CMAKE_INSTALL_PREFIX=${DIST} \
14+
-D WAMR_BUILD_SIMD=0 \
15+
../..
16+
cmake --build build-wamr -t install
17+
18+
cmake -B build-app \
19+
-D CMAKE_PREFIX_PATH=${DIST} \
20+
-D CMAKE_INSTALL_PREFIX=${DIST} \
21+
.
22+
cmake --build build-app
23+
24+
./build-app/printversion

0 commit comments

Comments
 (0)