Skip to content
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

build: initial support for meson build system #902

Open
wants to merge 16 commits into
base: master
Choose a base branch
from

Conversation

mochaaP
Copy link

@mochaaP mochaaP commented Feb 8, 2025

Initial support for meson build system.
I plan to maintain this port continuously alongside cmake.

suppoted features

xrefs

mesonbuild/wrapdb#1865
#761

tested

  • linux gcc
  • mingw gcc (cross)
  • mingw gcc (msys2)
  • mingw clang (msys2)
  • msvc (cross)
  • clang-cl
  • apple clang

meson.build Outdated Show resolved Hide resolved
Comment on lines +130 to +163
generator(
find_program('cp', 'xcopy'),
output: ['@PLAINNAME@'],
arguments: ['@INPUT@', '@OUTPUT@'],
).process(qjs_hdrs),
Copy link

Choose a reason for hiding this comment

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

There is import('fs').copyfile() for this. Though I'm confused why you're copying the header at all. Although it seems like you're doing this to try to put the header into a unique directory?

Copy link
Author

Choose a reason for hiding this comment

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

generator puts this into the target's private directory, and i reused that for declare_dependency to expose only the public headers.

i agree this is dirty. it should be better to change the directory structure, but @saghul might want to comment on this first.

Copy link
Contributor

Choose a reason for hiding this comment

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

Changing the directory structure is not on the table, sorry.

Many users still embed QuickJS by directly referencing the handful of files and we'd like to keep it that way for now.

Copy link

Choose a reason for hiding this comment

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

Understandable.

The other workaroud people will use for this it to have an include/meson.build that does the copying so that it gets laid out correctly in the working directory. This is a long standing but thorny issue for us (Meson) to fix.

meson.build Outdated Show resolved Hide resolved
examples/meson.build Outdated Show resolved Hide resolved
meson.build Outdated
qjsc_exe = executable(
'qjsc',
qjsc_srcs,
qjs_libc_srcs,
Copy link

Choose a reason for hiding this comment

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

This will cause all of these sources to be re-compiled for the executable, but then it seems like you link them back in via the qjs_dep.

Copy link
Author

Choose a reason for hiding this comment

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

qjs_libc_srcs == [] if -Dlibc=true, since it's already compiled in the main qjs_lib.
this variable is here to explicitly add quickjs-libc to required targets. is it better to use qjs_libc_lib = static_library(...) and then add link_whole: qjs_libc_lib to qjs_lib?

Copy link
Author

Choose a reason for hiding this comment

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

applied the qjs_libc_lib thing.

@dcbaker
Copy link

dcbaker commented Feb 8, 2025

I saw your comments on the wrap proposal, and thought I might take a peak at what you where working on.

@saghul
Copy link
Contributor

saghul commented Feb 8, 2025

Prior art: #761

@mochaaP mochaaP force-pushed the mochaa branch 2 times, most recently from 24aba70 to 42cb912 Compare February 8, 2025 20:09
@trim21
Copy link

trim21 commented Feb 8, 2025

I'm the author of mesonbuild/wrapdb#1865 . Then initial motivation is that we do not want to add meson.build in this project. If we are going to support meson build system natively I'll close mesonbuild/wrapdb#1865 because it's unnecessary

@saghul
Copy link
Contributor

saghul commented Feb 8, 2025

I'm the author of mesonbuild/wrapdb#1865 . Then initial motivation is that we do not want to add meson.build in this project. If we are going to support meson build system natively I'll close mesonbuild/wrapdb#1865 because it's unnecessary

Personally I'm still on the fence about adding Meson support here. If wrapdb is there then users already have a good way forward.

@bnoordhuis
Copy link
Contributor

I'm mildly negative on the changes to the Makefile. A meson build file, okay, but only if I don't have to look at it or think about it too much. For testing it, I'd add a CI job.

@dcbaker
Copy link

dcbaker commented Feb 8, 2025

From Meson's perspective we would prefer if meson.build files could live upstream, even with a lower level of support that $main_build_system. WrapDB can still reference projects with upstream meson.build files to make meson wrap install quickjs-ng work seemlessly.

meson.build Show resolved Hide resolved
meson.build Outdated Show resolved Hide resolved
meson_options.txt Outdated Show resolved Hide resolved
@dcbaker
Copy link

dcbaker commented Feb 8, 2025

LGTM from a meson is correct point of view

@saghul
Copy link
Contributor

saghul commented Feb 9, 2025

@bnoordhuis whats your appetite towards this? I'm somewhere around -0.5

@chqrlie
Copy link
Collaborator

chqrlie commented Feb 9, 2025

I'm mildly negative on the changes to the Makefile. A meson build file, okay, but only if I don't have to look at it or think about it too much. For testing it, I'd add a CI job.

Regarding changes to the Makefile and a choice of a build option, I am nor negative but I would favor an option to build directly from Makefile on selected targets, without CMake :)

@saghul
Copy link
Contributor

saghul commented Feb 9, 2025

@chqrlie Please let's keep this about meson.

@bnoordhuis
Copy link
Contributor

@bnoordhuis whats your appetite towards this? I'm somewhere around -0.5

I'm okay with merging it provided it's close-to-zero effort to maintain. I don't care for it myself but there's no denying meson is pretty popular nowadays.

Having said that, since wrapdb exists, is there a compelling reason to have the build file in this repo?

@dcbaker
Copy link

dcbaker commented Feb 9, 2025

Having them upstream means that your users can use git snapshots and git submodules as subprojects, that’s not possible with meson files hosted in wrapdb

@bnoordhuis
Copy link
Contributor

That's a good reason. @saghul, up to you.

@saghul
Copy link
Contributor

saghul commented Feb 10, 2025

Alright, let's give it a try. I'll give it a deeper look this week. What this PR is missing is a few CI jobs, to make sure this thing works at all :-)

@mochaaP
Copy link
Author

mochaaP commented Feb 10, 2025

sure, i will add it

@mochaaP
Copy link
Author

mochaaP commented Feb 10, 2025

should I add this to a separate workflow or just ci.yml?

@saghul
Copy link
Contributor

saghul commented Feb 10, 2025

Same file, new jobs.

@mochaaP mochaaP force-pushed the mochaa branch 2 times, most recently from 3c67859 to d5deb43 Compare February 10, 2025 11:41
@mochaaP
Copy link
Author

mochaaP commented Feb 10, 2025

clang sanitized builds fail with: runtime error: call to function js_realloc_rt through pointer to incorrect function type 'void *(*)(void *, void *, unsigned long)

@saghul
Copy link
Contributor

saghul commented Feb 10, 2025

In quickjs-libc?

Any way to get more output from the meson runners? They seem to output to a file.

@mochaaP
Copy link
Author

mochaaP commented Feb 10, 2025

@saghul
Copy link
Contributor

saghul commented Feb 10, 2025

Can you try if this helps?

diff --git a/quickjs-libc.c b/quickjs-libc.c
index e784878..c8892d2 100644
--- a/quickjs-libc.c
+++ b/quickjs-libc.c
@@ -170,9 +170,15 @@ typedef struct JSThreadState {
 
 static uint64_t os_pending_signals;
 
+static void *js_std_dbuf_realloc(void *opaque, void *ptr, size_t size)
+{
+    JSRuntime *rt = opaque;
+    return js_realloc_rt(rt, ptr, size);
+}
+
 static void js_std_dbuf_init(JSContext *ctx, DynBuf *s)
 {
-    dbuf_init2(s, JS_GetRuntime(ctx), (DynBufReallocFunc *)js_realloc_rt);
+    dbuf_init2(s, JS_GetRuntime(ctx), js_std_dbuf_realloc);
 }
 
 static bool my_isdigit(int c)

@saghul
Copy link
Contributor

saghul commented Feb 11, 2025

Looks like tests are failing here now: Failed: JS_IsJobPending(rt), file ../interrupt-test.c, line 114 but I have no idea why 😮

@bnoordhuis
Copy link
Contributor

Can meson be configured to just print the test output instead of logging it to a file? I don't want to download and unzip a file every time something goes wrong.

The test failure suggests somehow the async function job didn't get scheduled, although I have no idea how that could happen.

@mochaaP
Copy link
Author

mochaaP commented Feb 13, 2025

@bnoordhuis addressed in c354670

@saghul
Copy link
Contributor

saghul commented Feb 13, 2025

I wonder if we simply don't run that test under any sanitizer in the cmake build.

@bnoordhuis
Copy link
Contributor

It's tested under both asan+ubsan and msan and passes successfully.

@bnoordhuis
Copy link
Contributor

@mochaaP does the test fail or pass locally for you?

@mochaaP
Copy link
Author

mochaaP commented Feb 15, 2025

yes, it fails:

image

@saghul
Copy link
Contributor

saghul commented Feb 15, 2025

Can you spots what do the failed jobs have in common?

Comment on lines 760 to 765
# ASLR with big PIE slides does not work well with [AM]San
- name: disable ASLR
if: ${{ matrix.platform == 'ubuntu-latest' && contains(matrix.mode.name, 'san') }}
run: |
sudo sysctl -w kernel.randomize_va_space=0
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
# ASLR with big PIE slides does not work well with [AM]San
- name: disable ASLR
if: ${{ matrix.platform == 'ubuntu-latest' && contains(matrix.mode.name, 'san') }}
run: |
sudo sysctl -w kernel.randomize_va_space=0

Should not be necessary anymore after 9c25179

Copy link
Author

Choose a reason for hiding this comment

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

done

meson.build Outdated
Comment on lines 438 to 443
# Interrupt test
test(
'interrupt',
executable(
'interrupt-test',
'interrupt-test.c',
Copy link
Contributor

Choose a reason for hiding this comment

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

Was renamed in 22cd6ab.

Suggested change
# Interrupt test
test(
'interrupt',
executable(
'interrupt-test',
'interrupt-test.c',
# API test
test(
'api',
executable(
'api-test',
'api-test.c',

Copy link
Author

Choose a reason for hiding this comment

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

done

'bigint64_arith',
'bigint256_arith',
]
benchmark(
Copy link
Contributor

Choose a reason for hiding this comment

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

When does this run? If the CI doesn't exercise it, it's virtually guaranteed to get out of sync sooner or later.

Copy link
Author

Choose a reason for hiding this comment

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

added.

@mochaaP
Copy link
Author

mochaaP commented Feb 19, 2025

@saghul:

Can you spots what do the failed jobs have in common?

After a few days of troubleshooting, seems the tests will only fail with -O0 on clang. Should we use debugoptimized instead?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants