-
Notifications
You must be signed in to change notification settings - Fork 189
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
Integrate Meson as optional build system #262
base: master
Are you sure you want to change the base?
Conversation
This commit brings the meson build system branch up-to-date with the current CMake build system. It should be possible now to build and test flatcc using the Meson build system, like so: $ meson setup build $ meson compile -C build $ meson test -C build This is not yet integrated with the shell scripts in the scipts directory.
UBSan warns when passing a NULL as the src argument to memcpy. Avoid doing that.
This commit reorganizes the build scripts while also integrating Meson into the system.
This commit adds a new job to the CI workflow which builds, runs the tests, and the benchmarks under meson on Linux, Windows and macos. The benchmark code up until now was not compiled with the same flags as the library and runtime and so had avoided some scrutiny from these warnings. Under Meson this is no longer the case, and so this code has been fixed up to clean up some warnings
Thank you very much, I'll review this later, but a few quick observations:
There are also changes to other build scripts, possibly a refactoring, I haven't looked closely. But essentially, the changes might be fine, but they should apply independently of whether meson is included or not. |
Also, I noted that you updated Appveyor but it is OK to focus on GH Actions. I forgot to mention that we will eventually probably replace Appveyor fully with GH Actions, but currently it builds more windows and MSVC versions that the GH actions build does (contribs welcome on that front). |
$ ./scripts/initbuild.sh # this loads build.cfg.cmake (and hence ninja) by default
$ ./scripts/initbuild.sh meson # this loads build.cfg.meson
$ ./scripts/initbuild.sh make-* # this loads build.cfg.make-* So users who currently use
So there are two source changes:
Please let me know how you feel about these. I can rework or remove them if that suits better.
Indeed, there was quite a bit of refactoring to accommodate the inclusion the Meson configuration. I tried to make it so that the existing behaviour is maintained for current users and that only those who opt-in explicitly to meson will build with meson, and so my changes were implemented with that in mind. Many thanks, and I look forward to your feedback. |
Any updates on this? |
Sorry, glad you are asking. I'm a bit busy right now, but I have definitely not forgotten about it. |
@amcn heads up - I'm starting to do the review, if you are still willing to follow up on this. Overall I think it is great work, I'm just focusing on the details to get it into a mature and polished state. I will not review all the individual meson.build files. I trust they are OK if tests pass, and they seem to do that at least on my machine (MacOS Sonoma M2 chip). as to the checks on this PR: the windows meson build commit has lines like these:
I'm not sure this the is best option. If you build with clang or mingw you probably want the same conventions as the other targets (I'm not sure, but I think so, haven't checked what CMake build does), so you are likely looking for a MSVC check. On your above comments: "... mostly warnings ... "The benchmark code is now compiled with the same flags" A few comments: I just got meson 1.2.2 on MacOS Sonoma. I get some warnings. I have not tried to examine these closely, so this is just FYI for now, and non-exhaustive: When subsequently running I'm not sure about these ld warnings, could also be my machine, but I think / thought I just got that cleaned up. That said I'm getting some 8+ second execution time on meson with scripts/test.sh (which also cleans and rebuilds on both debug and release), and 9+ secons with cmake, so in same ballpark, both using meson. I like that you have set c_std=c11 and cpp_std=c++11 in root meson.build. This is the target platform. Wrt. meson and the build rules from the old meson branch 0.4, I trust you have testet dependencies including trying to change an indirect header or included schema file, otherwise please verify this. I'm not going into this level of detail in my review. |
I don't know why the build doesn't run, as I wrote above, but I made a temporary separate branch and merged with latest and master and it builds fine. EDIT: I spoke too soon. I ran the weekly build and all standard builds passes, but the build to check CMake version fails. The same build does pass on the main branch: I'm note sure if it is CMake version related, but we will probably upgrade min CMake. |
I did not look through all benchmark code, but some casts you have made are semantically different from the original:
vs
There are other examples like |
Thank you for your feedback! I will take another look at this PR and integrate your feedback as soon as possible. It has been a few months since I looked at this PR, so I will need some time to refresh my memory. Just as a side-note: I implemented this branch because I needed something like flatcc for a work project which is built via meson. After this PR was pushed I started making use of this branch in this work project and I would like to thank you for your work on flatcc: it's been a very nice library to work with. I absolutely do not want to break anything for existing users, so I will make especially sure to take your feedback about that into account. |
@amcn I'm glad it worked out for you, and thanks for working on this. Wrt. sanitizers, there have been other PRs like #237, and commits on this topic. So I just made the commit 0e925e1 to add the sanitizer flag to clang debug and fix source code accordingly (which still does not address benchmarks). |
aeccd46
to
56d2559
Compare
@amcn are you still working on this PR? We use flatcc downstream in our nanoarrow library and have also been using the Meson wrapdb for distribution, so this would be a great fit for us. Happy to try and pick up where this left off and push over the finish line if you could use help |
@mikkelfj Apologies for not having come back to this, I had forgotten admittedly. My original intention was motivated by a need I had at my previous workplace and in the intervening time that company and its product have since ceased to exist. Incidentally @WillAyd, I was using flatcc so that I could implement an Arrow IPC interface in C, much like nanoarrow (although nanoarrow's implementation seems to be much better than mine). It's a funny old world. I will take another look at this and try to address as many of the comments as possible in order to get it ready for merging. |
'c', 'cpp', | ||
version : '0.6.1', | ||
license : 'Apache-2.0', | ||
default_options : ['c_std=c11', 'cpp_std=c++11', 'default_library=static'], |
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.
I don't think you need to add default_library=static
here; the user can configure how they want to do this via a command line option, or Meson will intelligently handle this for you away (i.e. if used as a subproject, Meson will build this as static anyway)
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.
Found some time to work on this. So the reason I added default_library=static
originally is to make Windows build correctly on the CI. Ultimately without this, Meson's library()
generates a DLL. Given that flatcc currently does not explicitly export any symbols from this DLL by setting __declspec(dllexport)
on any symbols, MSVC does not create any import lib flatcc.lib
causing subsequent links to this library to fail, notably the flatcc cli tool. By forcing the generation of a static library, the link problems are avoided.
I've been trying various ways to get around this including both_libraries()
, but nothing seems to produce a linkable library on Windows. I think that the best path forward is to leave this as it is default_library=static
specified in the toplevel Meson script, and if users want to specify --default-library=shared
on the command-line then they are free to, but with the knowledge that this will cause Windows link failures. This mirrors CMake's -DBUILD_SHARED_LIBS=on
option, which when activated with flatcc also causes Windows link failures due to missing import libs.
I have a local patch with explicitly adds __declspec(dllexport)
to flatcc's public API, which seems to resolve the issue for both Meson and CMake, but if such a patch is ever considered for submission to flatcc, I think it would be best to do it separately from this PR. It touches lots of files.
TL;DR: On Windows, neither Meson nor CMake is currently capable of building and linking a shared version of flatcc, so default to static under Meson as is already the case under CMake.
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.
Ah OK that makes sense. I ran into a similar issue with nanoarrow last month - the advice I received from upstream was to do something like:
if is_windows
libtype = 'static_library'
else
libtype = 'library'
endif
build_target(
....,
target_type: libtype,
)
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.
Of course could also try to properly export symbols and simulate the issues by setting -fvisibility=hidden
for gcc, but that would require changes to the flatcc code itself
# It is not needed for some non-compliant compilers such as | ||
# recent gcc and clang. | ||
|
||
option('flatcc_portable', type : 'boolean', value : false) |
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.
Although common in CMake you don't need to prefix the options with flatcc
; if needed in Meson you can add the library name as a prefix to things anyway, so -Dflatcc:portable
would look for the flatcc library and set the portable flag.
Of course if you are just compiling from flatcc you don't need to specify this, and could just go with the shorter -Dportable=
command line argument
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.
Makes sense, I've removed the flatcc_
prefix for all the options as you suggested. I'll push up a new version of this PR in the near future once I have implemented as much of the feedback as possible.
@amcn Sorry I have not been able to respond timely. I will get back to you on this when I am able focus more on this project, if you are still up for it. |
Apologies, the inherent trauma of the human experience has been a particularly heavy burden these last few months and I have neglected many responsibilities as a result. I do still aim to get this into shape so that it can be merged and others can make use of it. |
I noticed something when working on getting the Windows side of this PR into shape: there seems to be unreachable code in src/compiler/codegen_schema.c. msvc looks at this block between the two |
Thanks for looking into this. Yes it does look suspicious. It it is probably the least bad place it could be though, since it seems to only affect the binary schema generated for a not so often used schema feature. Probably needs a review to see if the skipped code is actually correct before removing the break. Could be a bad merge. I too sense the flux of the essence of being, but will try to get back to you on this PR soon. |
What does this PR do?
it updates the existing meson branch against master making various changes here and there to get it to match the existing system. It's now possible to build, run the tests, and the benchmarks under meson using the following commands:
In addition, the shell scripts in the
scripts
directory have been updated to allow one to specify Meson as the build system alongside the existing build configurations using CMake. This required some changes to a number of scripts and configurations. Careful review of this would be appreciated, as I am unsure if my changes are acceptable.A job has been added to the CI workflow which builds, runs the tests, and the benchmarks under Linux, OSX, and Windows. This job has been set to not block the overall workflow if it fails.
While care has been taken to match the existing behaviour with that of CMake, I am sure that I have missed some things. There are probably also old things from the previous Meson branch that are now not useful.
Motivation
This solves a use case I have: using flatcc as a subproject of a system that is built with meson. With these changes in master (and a small subsequent push to meson's wrapdb) it should be possible for users of meson to get access to flatcc by doing the following:
and then using it directly in their build definitions:
I welcome your feedback. This aims to respond to #56 .