-
Notifications
You must be signed in to change notification settings - Fork 250
CMake/meson fixes, Windows support for shared lib build #1225
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
Conversation
|
As far as I'm aware, the CI failures are not caused by these changes |
|
Ping. Any updates? |
82ecdd0 to
3aec58b
Compare
|
I've triggered the CI again. IIRC the failures were directly related to this change, but let's see. |
|
I'm fine with this change. @saghul? edit: cross-wired |
|
I've been going through CI and stumbled upon this: https://github.com/quickjs-ng/quickjs/actions/runs/19475324220/job/55744866380?pr=1225#step:7:42 |
|
I can reproduce the failure on my machine too (albeit with clang only). |
|
https://github.com/google/sanitizers/wiki/AddressSanitizer#faq:
|
|
Meson option |
|
Passing |
3aec58b to
7b63c89
Compare
|
Should fix the CI. |
|
Yeah so as I said, the meson CI needs updating now to statically link by default. |
|
Would you like to me to do the CI update (including the fix for the failing CI for this PR) in this PR or separately? |
In this PR please, we like to avoid merging failing PRs. |
Your release CI builds QuickJS-NG with CMake so this PR shouldn't affect that. |
|
Apparently, for MSVC CI, we're hitting mesonbuild/meson#13892. Will add a commit forcing MSVC-based builds to use static libs. |
|
@BalkanMadman ping, seems this was close to done? |
7b63c89 to
6cd329f
Compare
|
Hello! Sorry for the delay, could you please try running the CI again? The two new commits should fix two issues in building QuickJS-NG shared. |
5b8d06a to
0cf1f7f
Compare
|
Okay, I also need to guard all the dll{export,import} shenanigans if we're building static libqjs🔥🔥🔥 Because obviously just exporting symbols isn't enough and on Windows you need separate exports for DLLs and static libs👍 |
|
Not sure I get the unconditional define in quickjs.c. Shouldn't it be set by Meson depending on the build type? |
0cf1f7f to
d0fe4c0
Compare
|
Looks like there are conflicts, can you rebase? |
d0fe4c0 to
704fed0
Compare
CMakeLists.txt
Outdated
| # We shouldn't really support building examples with static qjs.. | ||
| # Anyways, this is required for fib.so and point.so to link properly. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| # We shouldn't really support building examples with static qjs.. | |
| # Anyways, this is required for fib.so and point.so to link properly. | |
| # Required for fib.so and point.so to link properly. |
Because why shouldn't we support it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good question, you're right. I'll adjust the check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Completely revamped the check. Since runtime modules shouldn't link to qjs directly but rather use its symbols at runtime, I added an INTERFACE library for modules in CMake and the same dep in meson.
cc1ac41 to
38ffa75
Compare
|
All suggestions applied. Will test the JS_MODULE_EXTERN commit on Windows right now. |
|
Oh yes the classic "our platform is crippled and we can't resolve symbols at runtime". |
Previously, irrespective of the setting of -Dlibc, quickjs-libc would be built as a static library. In case -Dlibc=true is set, the static library is linked in libqjs only. In case -Dlibc=false is set, the archive is linked to every quickjs-libc consumer. In the former case (-Dlibc=true), building quickjs-libc as static library introduces useless indirection, since quickjs-libc is going to be linked only to libqjs anyway. CMake just adds the libc's sources to qjs's and calls it a day. This commit changes meson.build. If -Dlibc=true is set, quickjs-libc's sources are compiled as a part of libqjs. If not, it compiled as a static library, as was done before. In both cases, a direct dependency of quickjs-libc has been changed into a `dependency` on qjs_libc_dep which conveniently abstracts both configuration. So, if quickjs-libc needs to be linked to, just add `dependencies: qjs_libc_dep`. Signed-off-by: Zurab Kvachadze <zurabid2016@gmail.com>
Previously, if QJS_BUILD_LIBC was false, quickjs-libc would be built with every consumer. This made it harder to specify and trace the dependencies/compiler definitions of quickjs-libc itself. With this change, if -DQJS_BUILD_LIBC=false is passed to CMake, quickjs-libc is built as a normal static library, with its own compiler definitions and dependencies. This changes CMake to match the Meson behaviour. Additionally, since CMake does not allow mixing keyword and non-keyword declarations, this commit adds explicit `PRIVATE` to all `target_link_libraries` declarations. Signed-off-by: Zurab Kvachadze <zurabid2016@gmail.com>
ae41959 to
0028b63
Compare
|
Okay, restored the old behaviour of linking to |
|
There's still a windows-mingw-shared build error: |
|
Well, that's a new one. I gotta look through |
0028b63 to
c95d26f
Compare
|
Figured it out: both libqjs and qjs export symbols with implib having the same name which trips Ninja. Should be fixed now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Updates QuickJS-NG’s public headers and build scripts (Meson/CMake) to better support Windows DLL builds and consistent symbol export/import behavior across the core library, libc, and binary modules.
Changes:
- Introduces platform/compiler-aware
JS_EXTERN/JS_LIBC_EXTERN/JS_MODULE_EXTERNmacros and updates module/libc headers and examples to use them. - Refactors Meson and CMake builds to separate
cutils.cinto its own library and adjusts link/dependency wiring for shared builds and Windows modules. - Tweaks CI Meson sanitizer configurations to disable undefined-symbol enforcement in certain Clang sanitizer jobs.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
quickjs.h |
Adds export/import and module/libc extern macros for Windows/shared builds. |
quickjs-libc.h |
Switches libc API declarations to JS_LIBC_EXTERN. |
meson.build |
Refactors build graph (new cutils lib), adds shared/DLL compile defs, adjusts dependencies and pkg-config flags. |
examples/fib.c |
Uses <quickjs.h> and JS_MODULE_EXTERN for module entrypoint. |
examples/point.c |
Uses <quickjs.h> and JS_MODULE_EXTERN for module entrypoint. |
examples/meson.build |
Updates module build dependencies to use qjs_module_dep and hidden visibility. |
CMakeLists.txt |
Refactors build graph (new cutils lib), adds shared/DLL compile defs, introduces module interface target. |
.github/workflows/ci.yml |
Adds -Db_lundef=false to certain Meson Clang sanitizer modes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Ops, I clicked the copilot button by mistake! It did have some interesting things to say though! |
Since the macros like JS_EXTERN are used in more than one place, it is quite reasonable and helpful to declare them in one place. Additionally, the Windows support with the __declspec tango was missing. This commit, in addition to reorganising definitions, also plumbs Windows support for JS_EXTERN and JS_LIBC_EXTERN. Signed-off-by: Zurab Kvachadze <zurabid2016@gmail.com>
The new macro is a counterpart to JS_EXTERN, but for binary C modules. This commit introduces one more preprocessor define that must be set when building C modules. This commit changes examples/fib.c and examples/point.c to use the new macro, while also removing redundant JS_SHARED_LIBRARY. Additionally, the includes use the angled brackets now since quickjs.h is supposed to be external to the binary modules. meson.build is fixed to properly add the include directory; the manual header copying has also been removed as it is redundant. Signed-off-by: Zurab Kvachadze <zurabid2016@gmail.com>
Clang cannot handle building shared libraries with sanitizers and -Wl,--no-undefined (set by default unless explicitly disabled with -Db_lundef=false). This commit prefixes CI in case shared libraries are built with sanitisers. Signed-off-by: Zurab Kvachadze <zurabid2016@gmail.com>
During the build, the default library can be overridden via the -Ddefault_library=type flag. Presetting this key in meson.build makes life harder for distributions which almost always want to build shared libraries. Those requiring static libraries can always force that via the aforementioned flag. Signed-off-by: Zurab Kvachadze <zurabid2016@gmail.com>
c95d26f to
914ee1a
Compare
bnoordhuis
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM at a quick glance. Thanks!
saghul
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, nice work!
|
Thank you! |
Hello!
We've been packaging QuickJS-ng in Gentoo and we've found meson to be the most versatile amongst the added build systems. Huge thanks for taking care of QuickJS and implementing modern build systems -- it makes the life of us, packagers, much much easier.
This PR bundles two simple fixes for meson.build