-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Experimental support for building system libraries and ports with ninja. NFC #17809
Conversation
c7a7dbe
to
7899714
Compare
@walkingeyerobot I think ew can also generate bazel BUILD files in the same way? |
e4cf22c
to
78455fe
Compare
We can! There's a bit more wiring up that also has to be done that I'm currently working on, but I do plan to generate bazel BUILD rules similarly. |
This is really cool and I'm all in favor of transitioning to ninja instead of having our own code. |
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.
How does this work - do we have a persistent location for the object files? (we don't clean that up after each build?)
Does |
Ninja does work on all platforms (at least, all the platforms that Chrome builds on) and IIRC is a standalone binary. It's also widely available e.g. in Linux package managers, macports, (even npm!) etc. I don't think we bundle it in the emsdk already. It is a good question though, whether we want to take a hard dependency (which would allow us to remove our own library-building code, but would require all of our users to get it, and we'd want it in emsdk) or use our current code as a fallback (which would inevitably be less well-tested). |
tools/system_libs.py
Outdated
# Find a unique basename | ||
while o in objects: | ||
object_uuid += 1 | ||
o = f'{object_basename}__{object_uuid}.o' |
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 looks it's copied from build_objects but it's missing the initialization of object_basename.
Is it actually necessary though? it doesn't seem to be getting triggered.
I did get this working, but it turns out to have quite a few downsides. I have revive the patch I think but honestly I didn't get great results from it. I think the problem that this would solve is largely solved by the introduction of good dependencies. This should all but eliminate the need to ever clear the cache, which means a full rebuild should rarely be needed when working on the library code itself. One problem I ran into with the currently Regardless, this change will be useful as it stands and we can discuss the master-ninja thing later. |
Yes, these stick around in the cache, just like the downloaded tar archive and its expanded contents. Clearing the cache will clear them all. |
This will allow more easy transition to alternative build systems such as ninja (See #17809). Also, update build_port to allow separate source and build directories. This avoids copying the entire source code of each port from the extracts archive into the build directory.
tools/system_libs.py
Outdated
EMXX = {shared.EMXX} | ||
EMAR = {shared.EMAR} | ||
|
||
rule cc |
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.
If the real value is to use this for development, it seems we'll want to make sure that there are dependencies on the clang binaries, and potentially all of the python files, since changes to any of them could affect the object file output. Not all build systems do this properly, I can't recall whether Ninja is one of them.
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.
Oh yes.. that is unfortunately true. I had forgotten about that.
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.
My guess is that that full dependency graph would be too sensitive, but that this feature it most useful for folks working the libraries code and headers within emcripten.
This will allow more easy transition to alternative build systems such as ninja (See #17809). Also, update build_port to allow separate source and build directories. This avoids copying the entire source code of each port from the extracts archive into the build directory.
This will allow more easy transition to alternative build systems such as ninja (See #17809). Also, update build_port to allow separate source and build directories. This avoids copying the entire source code of each port from the extracts archive into the build directory.
This will allow more easy transition to alternative build systems such as ninja (See #17809). Also, update build_port to allow separate source and build directories. This avoids copying the entire source code of each port from the extracts archive into the build directory.
This will allow more easy transition to alternative build systems such as ninja (See #17809). Also, update build_port to allow separate source and build directories. This avoids copying the entire source code of each port from the extracts archive into the build directory.
This will allow more easy transition to alternative build systems such as ninja (See #17809). Also, update build_port to allow separate source and build directories. This avoids copying the entire source code of each port from the extracts archive into the build directory.
This will allow more easy transition to alternative build systems such as ninja (See #17809). Also, update build_port to allow separate source and build directories. This avoids copying the entire source code of each port from the extracts archive into the build directory.
This will allow more easy transition to alternative build systems such as ninja (See #17809). Also, update build_port to allow separate source and build directories. This avoids copying the entire source code of each port from the extracts archive into the build directory.
This will allow more easy transition to alternative build systems such as ninja (See #17809). Also, update build_port to allow separate source and build directories. This avoids copying the entire source code of each port from the extracts archive into the build directory.
This will allow more easy transition to alternative build systems such as ninja (See #17809). Also, update build_port to allow separate source and build directories. This avoids copying the entire source code of each port from the extracts archive into the build directory.
27b49d5
to
1753bf1
Compare
PTAL. I could split this up more but I think its fairly concise as is. |
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 looks pretty good in general
# This means we can avoid completely rebuilding a library and just rebuild based on what changed. | ||
# | ||
# Setting EMCC_USE_NINJA=2 means that ninja will automatically be run for each library needed at | ||
# link time. |
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 understand the difference between 1 and 2 in this comment. Reading the code, it seems like in mode 2 we force rebuilding of all libraries, even ones already built?
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 kind of. 2
means than whenever we need access to a given library we re-run the ninja file.. which will then do all the dependency checks as rebuild as needed. This mean you can edit e.g. dlmalloc.c and then just run emcc hello.c
and it will trigger the rebuilding of just that one file in that one library.
1
will use ninja to build things but won't run the ninja files at all if that libraries already exist.. you don't get the "edit" + emcc
+ "everything just works" workflow.
This interface isn't final or ideal, its just something I came up with for this experimental phase.
`clear_project_build` is already called each time a new vesion of a port is extracted. There is no reason to also clear the build directory during the `create` call. This helps with #17809 and also simplifies the code in each port.
`clear_project_build` is already called each time a new vesion of a port is extracted. There is no reason to also clear the build directory during the `create` call. This helps with #17809 and also simplifies the code in each port.
Waiting from #17857 to land which will make this patch little less complex. |
c097a11
to
4a9334d
Compare
Smaller patch, less duplication of code. PTAL. |
The primary advantage of doing this is that it avoids having force a completely rebuild of a system library when you want to rebuilt it. Instead not have precise dependencies.
We may start using it internally in emscripten. See emscripten-core/emscripten#17809
We may start using it internally in emscripten. See emscripten-core/emscripten#17809
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.
seems like the ports.write_file refactoring could be a separate change but if that's hard then LGTM, it's not too bad as it is.
Yes, I could have split that out too, although the main point of that is to avoiding re-writing header files with the same content, which is purely to avoid updating the timestamp which is only useful for the ninja build which uses timestamps to track dependencies. |
The primary advantage of doing this is that it avoids having force
a complete rebuild of a system library when you want to rebuilt it.
Instead not have precise dependencies.
Marking as NFC because this doesn't have any effect unless
EMCC_USE_NINJA
is set.