Skip to content

build: initial support for meson build system #902

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
215 changes: 206 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
run: |
make codegen
- name: Check if the git repository is clean
run: $(exit $(git status --porcelain --untracked-files=no | head -255 | wc -l)) || (echo "Dirty git tree"; git diff; exit 1)
run: (exit "$(git status --porcelain --untracked-files=no | head -255 | wc -l)") || (echo "Dirty git tree"; git diff; exit 1)

ci:
runs-on: ${{ matrix.config.os }}
Expand Down Expand Up @@ -418,7 +418,7 @@ jobs:
- name: build
run: |
emcmake cmake -B build -DQJS_BUILD_LIBC=ON
emmake make -C build qjs_wasm -j$(getconf _NPROCESSORS_ONLN)
emmake make -C build qjs_wasm "-j$(getconf _NPROCESSORS_ONLN)"
- name: result
run: ls -lh build
wasi:
Expand Down Expand Up @@ -509,10 +509,10 @@ jobs:
run: |
mkdir build
cd build
$ANDROID_HOME/cmake/3.22.1/bin/cmake -DCMAKE_TOOLCHAIN_FILE=$ANDROID_HOME/ndk/26.0.10792818/build/cmake/android.toolchain.cmake -DCMAKE_BUILD_TYPE=Release -DANDROID_ABI="arm64-v8a" -DANDROID_PLATFORM=android-24 -DQJS_BUILD_LIBC=ON ..
"$ANDROID_HOME/cmake/3.22.1/bin/cmake" "-DCMAKE_TOOLCHAIN_FILE=$ANDROID_HOME/ndk/26.0.10792818/build/cmake/android.toolchain.cmake" -DCMAKE_BUILD_TYPE=Release -DANDROID_ABI="arm64-v8a" -DANDROID_PLATFORM=android-24 -DQJS_BUILD_LIBC=ON ..
- name: Build android arm64
run: |
$ANDROID_HOME/cmake/3.22.1/bin/cmake --build build --target qjs
"$ANDROID_HOME/cmake/3.22.1/bin/cmake" --build build --target qjs
ls -lh build

ios:
Expand Down Expand Up @@ -585,13 +585,13 @@ jobs:
make amalgam
- name: build amalgamation
run: |
unzip -d $RUNNER_TEMP build/quickjs-amalgam.zip
cc -Wall -I. -o $RUNNER_TEMP/run-test262.o -c run-test262.c
cc -Wall -I/ -DQJS_BUILD_LIBC -o $RUNNER_TEMP/quickjs-amalgam.o -c $RUNNER_TEMP/quickjs-amalgam.c
cc -o $RUNNER_TEMP/run-test262 $RUNNER_TEMP/run-test262.o $RUNNER_TEMP/quickjs-amalgam.o -lm
unzip -d "$RUNNER_TEMP" build/quickjs-amalgam.zip
cc -Wall -I. -o "$RUNNER_TEMP/run-test262.o" -c run-test262.c
cc -Wall -I/ -DQJS_BUILD_LIBC -o "$RUNNER_TEMP/quickjs-amalgam.o" -c "$RUNNER_TEMP/quickjs-amalgam.c"
cc -o "$RUNNER_TEMP/run-test262" "$RUNNER_TEMP/run-test262.o" "$RUNNER_TEMP/quickjs-amalgam.o" -lm
- name: test
run: |
make test RUN262=$RUNNER_TEMP/run-test262
make test RUN262="$RUNNER_TEMP/run-test262"

jscheck:
runs-on: ubuntu-latest
Expand All @@ -600,3 +600,200 @@ jobs:
- name: jscheck
run: |
make jscheck

meson:
runs-on: ${{ matrix.platform }}
name: meson on ${{ matrix.platform }} (${{ matrix.mode.name }} ${{ matrix.flavor }}, ${{ matrix.features.name }})
strategy:
fail-fast: false
matrix:
flavor:
- debug
- release
features:
- name: default
args: ""
- name: libc
args: -Dlibc=true
- name: mimalloc
args: -Dcli_mimalloc=auto
- name: jscheck
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oooh i think i accidently forgot some leftovers from testing. cleaning it.

args: -Djscheck=true
mode:
- name: default
args: -Dtests=enabled
extra_envs: {}

# Alternative compiler setups
- name: gcc
args: -Dtests=enabled
extra_envs:
CC: gcc
CXX: g++
- name: clang
args: -Dtests=enabled
extra_envs:
CC: clang
CXX: clang++

- name: sanitize
args: >-
"-Db_sanitize=address,undefined"
extra_envs: {}

# This is for MSVC, which only supports AddressSanitizer.
# https://learn.microsoft.com/en-us/cpp/sanitizers/
- name: sanitize+asanonly
args: -Db_sanitize=address
extra_envs:
ASAN_OPTIONS: report_globals=0:halt_on_error=1:abort_on_error=1:print_summary=1

- name: clang+sanitize
args: >-
"-Db_sanitize=address,undefined"
extra_envs:
CC: clang
CXX: clang++
- name: clang+msan
args: -Db_sanitize=memory
extra_envs:
CC: clang
CXX: clang++

# default clang on GitHub hosted runners is from MSYS2.
# Use Visual Studio supplied clang-cl instead.
- name: clang-cl+sanitize
args: >-
"-Db_sanitize=address,undefined"
extra_envs:
CC: clang-cl
CXX: clang-cl
- name: clang-cl+msan
args: -Db_sanitize=memory
extra_envs:
CC: clang-cl
CXX: clang-cl
platform:
- ubuntu-latest
- windows-latest
- macos-latest

exclude:
# clang-cl only makes sense on windows.
- platform: ubuntu-latest
mode:
name: clang-cl+sanitize
- platform: macos-latest
mode:
name: clang-cl+sanitize
- platform: ubuntu-latest
mode:
name: clang-cl+msan
- platform: macos-latest
mode:
name: clang-cl+msan

# Use clang-cl instead of MSYS2 clang.
#
# we already tested clang+sanitize on linux,
# if this doesn't work, it should be an issue for MSYS2 team to consider.
- platform: windows-latest
mode:
name: clang
- platform: windows-latest
mode:
name: clang+sanitize
- platform: windows-latest
mode:
name: clang+msan

# MSVC-only sanitizers
- platform: ubuntu-latest
mode:
name: sanitize+asanonly
- platform: macos-latest
mode:
name: sanitize+asanonly
- platform: windows-latest
mode:
name: sanitize

# clang is the default on macos
# also gcc is an alias to clang
- platform: macos-latest
mode:
name: clang
- platform: macos-latest
mode:
name: gcc

# gcc is the default on linux
- platform: ubuntu-latest
mode:
name: gcc

# only run sanitizer tests on linux
#
# gcc/clang's codegen shouldn't massively change across platforms,
# and linux supports most of the sanitizers.
- platform: macos-latest
mode:
name: clang+sanitize
- platform: macos-latest
mode:
# macos does not support msan
name: clang+msan
- platform: macos-latest
mode:
name: sanitize

steps:
- name: Setup meson
run: |
pipx install meson ninja
- name: Install mimalloc
if: ${{ matrix.platform == 'ubuntu-latest' && matrix.features.name == 'mimalloc' }}
run: sudo apt update && sudo apt -y install libmimalloc-dev
- name: Install mimalloc
if: ${{ matrix.platform == 'macos-latest' && matrix.features.name == 'mimalloc' }}
run: brew install mimalloc
# TODO: Install mimalloc on Windows
# You need to:
# - checkout mimalloc
# - `msbuild mimalloc\ide\vs2022\mimalloc.sln`
# - not cmake, because https://github.com/microsoft/mimalloc/issues/575#issuecomment-1112723975
# - it is possible to integrate vcpkg with meson, but:
# - 1. the above issue
# - 2. the vcpkg port of mimalloc is outdated, and still broken on server 2019
# - or maintain a meson port for mimalloc (and ensure it behaves correctly)
# - Make it findable with cmake
# - not the simpler pkg-config. although there was pkg-config in PATH,
# but that was from strawberry perl and thus broken
# ... good job, microsoft :))))

- name: Checkout
uses: actions/checkout@v4
- name: Activate MSVC and Configure
if: ${{ matrix.platform == 'windows-latest' }}
env: ${{ matrix.mode.extra_envs }}
run: |
meson setup build-${{ matrix.flavor }} --buildtype=${{ matrix.flavor }} ${{ matrix.mode.args }} ${{ matrix.features.args }} --vsenv
- name: Configuring
if: ${{ matrix.platform != 'windows-latest' }}
env: ${{ matrix.mode.extra_envs }}
run: |
meson setup build-${{ matrix.flavor }} --buildtype=${{ matrix.flavor }} ${{ matrix.mode.args }} ${{ matrix.features.args }}
- name: Building
run: |
meson compile -C build-${{ matrix.flavor }}

- name: Running tests
env: ${{ matrix.mode.extra_envs }}
run: |
meson test -C build-${{ matrix.flavor }} --timeout-multiplier 5 --print-errorlogs
meson test --benchmark -C build-${{ matrix.flavor }} --timeout-multiplier 5 --print-errorlogs
- uses: actions/upload-artifact@v4
if: ${{ failure() }}
with:
name: ${{ matrix.platform }}-${{ matrix.mode.name }}-${{ matrix.features.name }}-${{ matrix.flavor }}-logs
path: build-${{ matrix.flavor }}/meson-logs
19 changes: 19 additions & 0 deletions examples/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
shared_module(
'fib',
'fib.c',

name_prefix: '',
gnu_symbol_visibility: 'default',
c_args: ['-DJS_SHARED_LIBRARY'],
dependencies: host_system == 'windows' ? qjs_dep : [],
)

shared_module(
'point',
'point.c',

name_prefix: '',
gnu_symbol_visibility: 'default',
c_args: ['-DJS_SHARED_LIBRARY'],
dependencies: host_system == 'windows' ? qjs_dep : [],
)
Loading
Loading