From 2ce924b33581dd6dcd56f8c8924c25a5d96e7177 Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Sun, 2 Aug 2026 16:18:18 -0700 Subject: [PATCH] Add example config and testing for meson build system This is a meta-build-system (like cmake) that generated Ninja by default. It pretty popular in certain open source communities. For example the whole Gnome and X.Org / Wayland is based on it. Add simple tests for the meson build system along with example cross files for `wasm32` and `wasm64` in `test/meson/`. * `test/meson/wasm32-emscripten.ini`: Cross file for wasm32 with `node` wrapper. * `test/meson/wasm64-emscripten.ini`: Cross file for wasm64 with `-m64` flags. * `test/meson/simple/`: C test project for standard Meson build. * `test/meson/simple_64/`: C test project for wasm64 Meson build. --- .circleci/config.yml | 5 +++++ ChangeLog.md | 2 ++ requirements-dev.txt | 5 ++++- test/meson/simple/main.c | 6 ++++++ test/meson/simple/meson.build | 3 +++ test/test_other.py | 24 +++++++++++++++++++++++- tools/meson/wasm32-emscripten.ini | 15 +++++++++++++++ tools/meson/wasm64-emscripten.ini | 21 +++++++++++++++++++++ 8 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 test/meson/simple/main.c create mode 100644 test/meson/simple/meson.build create mode 100644 tools/meson/wasm32-emscripten.ini create mode 100644 tools/meson/wasm64-emscripten.ini diff --git a/.circleci/config.yml b/.circleci/config.yml index 112e3eca1a3e8..86e2e42f26583 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -760,6 +760,7 @@ jobs: test-wasm64-misc: environment: LANG: "C.UTF-8" + EMTEST_SKIP_NINJA: "1" executor: ubuntu-lts steps: - prepare-for-tests @@ -790,6 +791,7 @@ jobs: executor: ubuntu-lts environment: EMTEST_SKIP_NEW_CMAKE: "1" + EMTEST_SKIP_NINJA: "1" EMTEST_SKIP_WASM64: "1" steps: - checkout @@ -807,6 +809,7 @@ jobs: executor: ubuntu-lts environment: EMTEST_SKIP_NEW_CMAKE: "1" + EMTEST_SKIP_NINJA: "1" steps: - checkout - pip-install @@ -1230,6 +1233,7 @@ jobs: EMTEST_SKIP_RUST: "1" EMTEST_SKIP_NODE_25: "1" EMTEST_SKIP_PKG_CONFIG: "1" + EMTEST_SKIP_MESON: "1" EMTEST_BROWSER: "0" steps: - checkout @@ -1271,6 +1275,7 @@ jobs: EMTEST_SKIP_WASM_EH: "1" EMTEST_SKIP_WASM64: "1" EMTEST_SKIP_SCONS: "1" + EMTEST_SKIP_MESON: "1" EMTEST_SKIP_RUST: "1" EMTEST_SKIP_NODE_25: "1" # Some native clang tests assume x86 clang (e.g. -sse2) diff --git a/ChangeLog.md b/ChangeLog.md index 9baef98bad25e..487728d67c1d8 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -23,6 +23,8 @@ See docs/process.md for more on how version tagging works. - `DEFAULT_TO_CXX` is now disabled by default. This means that `em++` is now required when linking C++ programs, matching the behavior of clang and gcc. The old behavior is still available using `-sDEFAULT_TO_CXX`. (#11121) +- Added example Meson cross compilation files (`wasm32-emscripten.ini` and + `wasm64-emscripten.ini`) in `tools/meson/`. (#27478) - libcxx and libcxxabi were updated to LLVM 22.1.8. (#27428) 6.0.5 - 07/29/26 diff --git a/requirements-dev.txt b/requirements-dev.txt index 84c746d35969d..9214b01b11bda 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -22,5 +22,8 @@ sphinx-design==0.6.1 sphinxcontrib-jquery==4.0 shibuya==2026.5.19 -# Needed by test/test_sockets.py +# Needed by tests in test_sockets.py websockify==0.12.0 + +# Needed by tests in test_other.py +meson==1.11.2 diff --git a/test/meson/simple/main.c b/test/meson/simple/main.c new file mode 100644 index 0000000000000..90f794715d97f --- /dev/null +++ b/test/meson/simple/main.c @@ -0,0 +1,6 @@ +#include + +int main(void) { + printf("sizeof pointer: %zu\n", sizeof(void*)); + return 0; +} diff --git a/test/meson/simple/meson.build b/test/meson/simple/meson.build new file mode 100644 index 0000000000000..bb9e434c9ab17 --- /dev/null +++ b/test/meson/simple/meson.build @@ -0,0 +1,3 @@ +project('simple', 'c') +exe = executable('hello', 'main.c') +test('simple_test', exe) diff --git a/test/test_other.py b/test/test_other.py index 4c30e88c20cfd..b95f8781bc561 100644 --- a/test/test_other.py +++ b/test/test_other.py @@ -248,7 +248,7 @@ def decorated(self, *args, **kwargs): env_var = f'EMTEST_SKIP_{tool.upper()}' if not shutil.which(tool): if env_var in os.environ: - self.skipTest(f'test requires ccache and {env_var} is set') + self.skipTest(f'test requires {tool} and {env_var} is set') else: self.fail(f'{tool} required to run this test. Use {env_var} to skip') return func(self, *args, **kwargs) @@ -3381,6 +3381,28 @@ def test_emscons_env(self): self.run_process([path_from_root('emscons'), 'scons', '--expected-env', expected_to_propagate]) + @crossplatform + @requires_tool('meson') + @requires_ninja + @with_env_modify({'PATH': path_from_root() + os.pathsep + os.getenv('PATH', '')}) + def test_meson(self): + self.run_process(['meson', 'setup', '.', test_file('meson/simple'), '--cross-file', path_from_root('tools/meson/wasm32-emscripten.ini')]) + self.run_process(['meson', 'compile', '-C', '.']) + output = self.run_js('hello.js') + self.assertContained('sizeof pointer: 4', output) + self.run_process(['meson', 'test', '-C', '.']) + + @requires_tool('meson') + @requires_ninja + @requires_wasm64 + @with_env_modify({'PATH': path_from_root() + os.pathsep + os.getenv('PATH', '')}) + def test_meson_wasm64(self): + self.run_process(['meson', 'setup', '.', test_file('meson/simple'), '--cross-file', path_from_root('tools/meson/wasm64-emscripten.ini')]) + self.run_process(['meson', 'compile', '-C', '.']) + output = self.run_js('hello.js') + self.assertContained('sizeof pointer: 8', output) + self.run_process(['meson', 'test', '-C', '.']) + def test_embind_fail(self): self.assert_fail([EMXX, test_file('embind/test_unsigned.cpp')], 'undefined symbol: _embind_register_function') diff --git a/tools/meson/wasm32-emscripten.ini b/tools/meson/wasm32-emscripten.ini new file mode 100644 index 0000000000000..fa8dd520eb6f6 --- /dev/null +++ b/tools/meson/wasm32-emscripten.ini @@ -0,0 +1,15 @@ +# Example Meson cross file for Emscripten (wasm32) +# Usage: meson setup builddir --cross-file tools/meson/wasm32-emscripten.ini + +[binaries] +c = 'emcc' +cpp = 'em++' +ar = 'emar' +ranlib = 'emranlib' +exe_wrapper = 'node' + +[host_machine] +system = 'emscripten' +cpu_family = 'wasm32' +cpu = 'wasm32' +endian = 'little' diff --git a/tools/meson/wasm64-emscripten.ini b/tools/meson/wasm64-emscripten.ini new file mode 100644 index 0000000000000..cbc54b8100770 --- /dev/null +++ b/tools/meson/wasm64-emscripten.ini @@ -0,0 +1,21 @@ +# Example Meson cross file for Emscripten (wasm64) +# Usage: meson setup builddir --cross-file tools/meson/wasm64-emscripten.ini + +[binaries] +c = 'emcc' +cpp = 'em++' +ar = 'emar' +ranlib = 'emranlib' +exe_wrapper = 'node' + +[built-in options] +c_args = ['-m64'] +c_link_args = ['-m64'] +cpp_args = ['-m64'] +cpp_link_args = ['-m64'] + +[host_machine] +system = 'emscripten' +cpu_family = 'wasm64' +cpu = 'wasm64' +endian = 'little'