-
Notifications
You must be signed in to change notification settings - Fork 202
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
[WIP] Add CMake build system #330
base: main
Are you sure you want to change the base?
Conversation
I know you mention some rational in #322, but I'm curious what you personal primary motivation is for wanting to make this change? I guess better native windows support is the big one? Without needing to setup something like mingw? I personally find cmake syntax and semantics pretty confusing (more so than the relative simplicity of a Makefile), but I get that its personal preference. This does seem to make some things more complex. For example, it looks like it takes roughly twice as many lines of code to implement. We would also be adding a python dependency. I'm generally a fan of python over shell scripts for this kind of thing but others might feel differently. |
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.
Could you add some instructions (maybe as a mod to the README) so I can try it out? I've love to give it go. Does this setup support out-of-tree building?
list(REMOVE_ITEM LIBC_BOTTOM_HALF_ALL_SOURCES ${CHDIR_SRC}) | ||
list(APPEND LIBC_BOTTOM_HALF_ALL_SOURCES ${CHDIR_SRC}) | ||
|
||
add_library(libc-bottom-half OBJECT |
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 guess this is some kind of "library" that getting somehow inlined into the main libc? More like a list of object files that a library per-say?
I assume all the object files that make up libc-bottom-half will still show up as individual object files within libc.a?
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.
Yes, they're just object files.
I'm also not sold on replacing |
In my opinion, it provides more watertight ways to ensure you have the pieces you need, also it has "first class types" for sub-targets like libraries, including dependence detection, this reduces risk of mistyping or having parts of the build go out of sync. It isn't a silver bullet, though. |
Pretty much what @penzn already mentioned but also having experience with both Makefile and CMake, I find both learning CMake and maintaining CMake project easier. I also think Makefile has a steeper learning curve than CMake but that may be because I
I wouldn't use number of lines as a metric for complexity. If needed, I could probably optimize (most likely at a cost of readability, although I didn't look into it).
I don't think this is relevant to Makefile vs CMake discussion. They both can run shell and python scripts; I copied it (and slightly modified) from previous PR because I found it more readable.
What I found is that creating a CMake project from scratch requires some knowledge, but most of the modifications don't often require looking into documentation, as you can do most of what you need based on already written code (I guess just like Makefile) |
I can definitely update the README file; meanwhile, here's a command you can use:
|
One concrete advantage of moving to CMake is that the current wasi-libc Makefile doesn't do dependency management correctly, so we effectively don't have incremental builds right now. |
f9d135e
to
082ec55
Compare
Yes, incremental build is a huge benefit, but I never listed it as a benefit because I'm not sure how hard is it to implement it for the existing Makefile. |
d9c4692
to
b984e91
Compare
b984e91
to
f64759d
Compare
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.
Part of why I had lost interest was the difficulty to get the proper support for CMake added due to upstream resistance.
enable_testing() | ||
|
||
if("${CMAKE_C_COMPILER}" MATCHES "(.*)clang(-[0-9]+)?$") | ||
set(CMAKE_NM "${CMAKE_MATCH_1}llvm-nm${CMAKE_MATCH_2}") |
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 would recommend against this. This prevents the user from specifying the name tool to use.
|
||
add_library(c) | ||
|
||
set (LIBC_LINK_LIBRARIES |
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.
This is an anti-pattern. Prefer to directly use the targets with target_link_libraries
libc-bottom-half | ||
) | ||
|
||
if(${BUILD_LIBC_TOP_HALF} STREQUAL "ON") |
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 tend to prefer the more concise spelling:
if(${BUILD_LIBC_TOP_HALF} STREQUAL "ON") | |
if(BUILD_LIBC_TOP_HALF) |
This has the benefit of allowing the user to specify the value with a truthy value that CMake permits (ON, YES, 1).
if(${BUILD_LIBC_TOP_HALF} STREQUAL "ON") | ||
list(APPEND LIBC_LINK_LIBRARIES | ||
libc-top-half | ||
) |
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.
Again, an anti-pattern. Prefer to use a generator expression with target_link_libraries
.
|
||
if(${MALLOC_IMPL} STREQUAL "dlmalloc") | ||
list(APPEND LIBC_LINK_LIBRARIES | ||
dlmalloc) |
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.
Similar
|
||
add_test(NAME check-headers | ||
COMMAND ${CMAKE_C_COMPILER} | ||
-target ${CMAKE_C_COMPILER_TARGET} |
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.
This prevents the use of any compiler other than clang.
@@ -0,0 +1,10 @@ | |||
set(DLMALLOC_DIR ${PROJECT_SOURCE_DIR}/dlmalloc) |
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.
Why the variable for a single use?
@@ -0,0 +1,39 @@ | |||
# WebAssembly floating-point match doesn't trap. | |||
# TODO: Add -fno-signaling-nans when the compiler supports it. | |||
add_compile_options(-fno-trapping-math) |
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.
You should validate that the compiler supports the option.
-Wno-ignored-pragmas | ||
-Wno-unused-but-set-variable | ||
-Wno-unknown-warning-option | ||
) |
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.
Similar
LIBC_BOTTOM_HALF_ALL_SOURCES | ||
CONFIGURE_DEPENDS | ||
${LIBC_BOTTOM_HALF_CLOUDLIBC_SRC_DIR}/*.c | ||
${LIBC_BOTTOM_HALF_SRC_DIR}/*.c) |
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.
This is a highly dubious. This will lose the ability to alter the sources. The glob is applied once at configure time and never again. You should explicitly list the sources. Similar throughout.
This is a work-in-progress PR and still require a few actions. I open the PR to get early feedback. Some of the changes are clone from the other attempt of migrating this repository to CMake build system: #154. One major difference between this change and the previous one is that I'm using install target to create sysroot; I find this to be a bit more natural than specifying destination for every target.
I tested the changes by diff-ing generated install directory with the sysroot generated by Makefile. I also compiled and ran a few apps on WAMR runtime.
Resolves #322