Skip to content

Conversation

@juj
Copy link
Collaborator

@juj juj commented Feb 14, 2021

This PR adds support for Ninja build system and ccache, to be built from source.

Needs a bit of code duplication cleanup in order to be able to land, but posting for visibility so that users can try it out.

The corresponding PR for emscripten is at emscripten-core/emscripten#13498 and the corresponding changes to ccache itself are at https://github.com/juj/ccache/tree/emscripten.

The general mechanism is that after activating ccache in Emscripten SDK, emcc and em++ will automatically take usage of the installed ccache tool.

Usage:

emsdk install sdk-upstream-master-64bit ccache-git-emscripten-64bit
emsdk activate sdk-upstream-master-64bit  ccache-git-emscripten-64bit
cd %EMSCRIPTEN%
git remote add juj https://github.com/juj/emscripten.git
git fetch emscripten
git checkout ccache

# Example 1: rebuilding libc is fast from cache:
ccache -s # check initial ccache statistics: zero compiled files in cache
emcc --clear-cache

python embuilder.py build libc # cache miss
ccache -s # will show 862 files missed cache

ccache -z # zero ccache statistics

emcc --clear-cache
python embuilder.py build libc # cache hit!
ccache -s # now shows 862 files found from cache

# Example 2: rebuilding custom code is fast from cache:
ccache -z # zero statistics
emcc -c tests\hello_world.c -o a.o # cache miss
ccache -s # shows one file missed cache
emcc -c tests\hello_world.c -o a.o # cache hit!
ccache -s # shows one file hit cache

"activated_cfg": "NINJA=%installation_dir%/bin",
"activated_path": "%installation_dir%/bin",
"cmake_build_type": "Release",
"custom_install_script": "build_ninja"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not just treat ninja like node an download the prebuilt binaries?

Looks like the zip files are easy to link to: https://github.com/ninja-build/ninja/releases

Or maybe just treat it like cmake itself and assume the developer has already installed it? Building from source seems like a less trodden path so have extra dependencies seems reasonable maybe? At least it seems like cmake and ninja should be treated in the same way.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Mainly because of being able to change up ninja code in a custom branch, because of getting direct Apple M1 Mac support this way, and to get backwards compatibility support against whichever Xcode SDK and Windows SDK that I compile for myself. (I don't know the guaranteed min OS versions of the precompiled releases).

Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we at least try it? or at least have "download binary" as the default way to download ninja? (then only folks with unusual OS/hardware need to build from source, like we do for llvm)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Do you have have patches to ninja planned?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I would not oppose adding prebuilt ninja as well, though I am not keen to work on that at the moment. Fortunately emsdk does allow a good structure to have both.

I do plan to change ninja to fix stdout printing issues on Windows. When one uses ninja, they lose colored output for error messages and all stdout gets needlessly buffered, resulting in EMCC_DEBUG being uncomfortable to use on Windows.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I would prefer to simply use ninja pre-built bit I'm OK landing this as is.

Regarding the specifics of the ninja buffering issue. Are you talking about how the buffering causes the tools to skip adding color to their output? I agree it would be nice to find a fix for this, but I also really like how ninja buffers command and output rather than the nasty interleaving one gets with make VERVOSE=1 -jN.

@juj
Copy link
Collaborator Author

juj commented Mar 13, 2021

Ping, any other reviews? If not, I'll proceed and land this.

Copy link
Collaborator

@sbc100 sbc100 left a comment

Choose a reason for hiding this comment

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

lgtm

"activated_cfg": "NINJA=%installation_dir%/bin",
"activated_path": "%installation_dir%/bin",
"cmake_build_type": "Release",
"custom_install_script": "build_ninja"
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would prefer to simply use ninja pre-built bit I'm OK landing this as is.

Regarding the specifics of the ninja buffering issue. Are you talking about how the buffering causes the tools to skip adding color to their output? I agree it would be nice to find a fix for this, but I also really like how ninja buffers command and output rather than the nasty interleaving one gets with make VERVOSE=1 -jN.

@juj
Copy link
Collaborator Author

juj commented Mar 15, 2021

Are you talking about how the buffering causes the tools to skip adding color to their output?

Yeah, that's right.

I also really like how ninja buffers command and output rather than the nasty interleaving one gets with make VERVOSE=1 -jN.

I think the right way is to do line buffering per each thread, and not character/printf segment buffering, but mingw32-make -j on Windows fails on doing that proper. Having multiple threads interleave the printed lines of their output is more desirable to me for responsiveness, rather than get a long silence that first makes you wonder if the build is hung (which can happen with python multiprocessing) and then a sudden flood of everything that got printed.

@juj juj merged commit 9c65611 into master Mar 15, 2021
@juj juj deleted the ccache branch March 15, 2021 07:15
@juj
Copy link
Collaborator Author

juj commented Mar 15, 2021

I would prefer to simply use ninja pre-built bit I'm OK landing this as is.

Not opposed at all with also having pre-built ninja packages in the manifest, but I don't find that so useful, mostly due to not getting M1 Mac Mini native ARM64 code, so not spending the time to work on that for now.

@sbc100
Copy link
Collaborator

sbc100 commented Mar 15, 2021

I would prefer to simply use ninja pre-built bit I'm OK landing this as is.

Not opposed at all with also having pre-built ninja packages in the manifest, but I don't find that so useful, mostly due to not getting M1 Mac Mini native ARM64 code, so not spending the time to work on that for now.

I see.. it hadn't occurred to me that there might not be a ninja binary for that platform yet. Thanks for clarifying.

@mr-c
Copy link

mr-c commented Feb 15, 2023

Thank you @juj for this work and the fork of ccache; have you submitted your enhancements upstream?

akoeplinger pushed a commit to akoeplinger/emsdk that referenced this pull request Dec 13, 2024
…otnet/llvm-project, dotnet/node, dotnet/source-build-reference-packages (emscripten-core#711)

* Update dependencies from https://github.com/dotnet/source-build-reference-packages build

Microsoft.SourceBuild.Intermediate.source-build-reference-packages
 From Version 9.0.0-alpha.1.24155.1 -> To Version 9.0.0-alpha.1.24162.2

* Update dependencies from https://github.com/dotnet/emscripten build

Microsoft.NETCore.Runtime.Wasm.Emscripten.Transport
 From Version 9.0.0-alpha.1.24161.1 -> To Version 9.0.0-alpha.1.24168.1

* Update dependencies from https://github.com/dotnet/source-build-reference-packages build

Microsoft.SourceBuild.Intermediate.source-build-reference-packages
 From Version 9.0.0-alpha.1.24155.1 -> To Version 9.0.0-alpha.1.24162.2

* Update dependencies from https://github.com/dotnet/llvm-project build

runtime.linux-arm64.Microsoft.NETCore.Runtime.JIT.Tools , runtime.linux-arm64.Microsoft.NETCore.Runtime.Mono.LLVM.Sdk , runtime.linux-arm64.Microsoft.NETCore.Runtime.Mono.LLVM.Tools , runtime.linux-arm64.Microsoft.NETCore.Runtime.Wasm.LLVM.Transport , runtime.linux-musl-arm64.Microsoft.NETCore.Runtime.JIT.Tools , runtime.linux-musl-arm64.Microsoft.NETCore.Runtime.Mono.LLVM.Sdk , runtime.linux-musl-arm64.Microsoft.NETCore.Runtime.Mono.LLVM.Tools , runtime.linux-musl-arm64.Microsoft.NETCore.Runtime.Wasm.LLVM.Transport , runtime.linux-musl-x64.Microsoft.NETCore.Runtime.JIT.Tools , runtime.linux-musl-x64.Microsoft.NETCore.Runtime.Mono.LLVM.Sdk , runtime.linux-musl-x64.Microsoft.NETCore.Runtime.Mono.LLVM.Tools , runtime.linux-musl-x64.Microsoft.NETCore.Runtime.Wasm.LLVM.Transport , runtime.linux-x64.Microsoft.NETCore.Runtime.JIT.Tools , runtime.linux-x64.Microsoft.NETCore.Runtime.Mono.LLVM.Sdk , runtime.linux-x64.Microsoft.NETCore.Runtime.Mono.LLVM.Tools , runtime.linux-x64.Microsoft.NETCore.Runtime.Wasm.LLVM.Transport , runtime.osx-arm64.Microsoft.NETCore.Runtime.JIT.Tools , runtime.osx-arm64.Microsoft.NETCore.Runtime.Mono.LLVM.Sdk , runtime.osx-arm64.Microsoft.NETCore.Runtime.Mono.LLVM.Tools , runtime.osx-arm64.Microsoft.NETCore.Runtime.Wasm.LLVM.Transport , runtime.osx-x64.Microsoft.NETCore.Runtime.JIT.Tools , runtime.osx-x64.Microsoft.NETCore.Runtime.Mono.LLVM.Sdk , runtime.osx-x64.Microsoft.NETCore.Runtime.Mono.LLVM.Tools , runtime.osx-x64.Microsoft.NETCore.Runtime.Wasm.LLVM.Transport , runtime.win-arm64.Microsoft.NETCore.Runtime.JIT.Tools , runtime.win-arm64.Microsoft.NETCore.Runtime.Wasm.LLVM.Transport , runtime.win-x64.Microsoft.NETCore.Runtime.JIT.Tools , runtime.win-x64.Microsoft.NETCore.Runtime.Mono.LLVM.Sdk , runtime.win-x64.Microsoft.NETCore.Runtime.Mono.LLVM.Tools , runtime.win-x64.Microsoft.NETCore.Runtime.Wasm.LLVM.Transport
 From Version 16.0.5-alpha.1.24161.3 -> To Version 16.0.5-alpha.1.24168.1

* Update dependencies from https://github.com/dotnet/binaryen build

runtime.linux-arm64.Microsoft.NETCore.Runtime.Wasm.Binaryen.Transport , runtime.linux-musl-arm64.Microsoft.NETCore.Runtime.Wasm.Binaryen.Transport , runtime.linux-musl-x64.Microsoft.NETCore.Runtime.Wasm.Binaryen.Transport , runtime.linux-x64.Microsoft.NETCore.Runtime.Wasm.Binaryen.Transport , runtime.osx-arm64.Microsoft.NETCore.Runtime.Wasm.Binaryen.Transport , runtime.osx-x64.Microsoft.NETCore.Runtime.Wasm.Binaryen.Transport , runtime.win-arm64.Microsoft.NETCore.Runtime.Wasm.Binaryen.Transport , runtime.win-x64.Microsoft.NETCore.Runtime.Wasm.Binaryen.Transport
 From Version 9.0.0-alpha.1.24163.4 -> To Version 9.0.0-alpha.1.24168.2

* Update dependencies from https://github.com/dotnet/emscripten build

Microsoft.NETCore.Runtime.Wasm.Emscripten.Transport
 From Version 9.0.0-alpha.1.24161.1 -> To Version 9.0.0-alpha.1.24168.1

* Update dependencies from https://github.com/dotnet/llvm-project build

runtime.linux-arm64.Microsoft.NETCore.Runtime.JIT.Tools , runtime.linux-arm64.Microsoft.NETCore.Runtime.Mono.LLVM.Sdk , runtime.linux-arm64.Microsoft.NETCore.Runtime.Mono.LLVM.Tools , runtime.linux-arm64.Microsoft.NETCore.Runtime.Wasm.LLVM.Transport , runtime.linux-musl-arm64.Microsoft.NETCore.Runtime.JIT.Tools , runtime.linux-musl-arm64.Microsoft.NETCore.Runtime.Mono.LLVM.Sdk , runtime.linux-musl-arm64.Microsoft.NETCore.Runtime.Mono.LLVM.Tools , runtime.linux-musl-arm64.Microsoft.NETCore.Runtime.Wasm.LLVM.Transport , runtime.linux-musl-x64.Microsoft.NETCore.Runtime.JIT.Tools , runtime.linux-musl-x64.Microsoft.NETCore.Runtime.Mono.LLVM.Sdk , runtime.linux-musl-x64.Microsoft.NETCore.Runtime.Mono.LLVM.Tools , runtime.linux-musl-x64.Microsoft.NETCore.Runtime.Wasm.LLVM.Transport , runtime.linux-x64.Microsoft.NETCore.Runtime.JIT.Tools , runtime.linux-x64.Microsoft.NETCore.Runtime.Mono.LLVM.Sdk , runtime.linux-x64.Microsoft.NETCore.Runtime.Mono.LLVM.Tools , runtime.linux-x64.Microsoft.NETCore.Runtime.Wasm.LLVM.Transport , runtime.osx-arm64.Microsoft.NETCore.Runtime.JIT.Tools , runtime.osx-arm64.Microsoft.NETCore.Runtime.Mono.LLVM.Sdk , runtime.osx-arm64.Microsoft.NETCore.Runtime.Mono.LLVM.Tools , runtime.osx-arm64.Microsoft.NETCore.Runtime.Wasm.LLVM.Transport , runtime.osx-x64.Microsoft.NETCore.Runtime.JIT.Tools , runtime.osx-x64.Microsoft.NETCore.Runtime.Mono.LLVM.Sdk , runtime.osx-x64.Microsoft.NETCore.Runtime.Mono.LLVM.Tools , runtime.osx-x64.Microsoft.NETCore.Runtime.Wasm.LLVM.Transport , runtime.win-arm64.Microsoft.NETCore.Runtime.JIT.Tools , runtime.win-arm64.Microsoft.NETCore.Runtime.Wasm.LLVM.Transport , runtime.win-x64.Microsoft.NETCore.Runtime.JIT.Tools , runtime.win-x64.Microsoft.NETCore.Runtime.Mono.LLVM.Sdk , runtime.win-x64.Microsoft.NETCore.Runtime.Mono.LLVM.Tools , runtime.win-x64.Microsoft.NETCore.Runtime.Wasm.LLVM.Transport
 From Version 16.0.5-alpha.1.24161.3 -> To Version 16.0.5-alpha.1.24168.1

* Update dependencies from https://github.com/dotnet/binaryen build

runtime.linux-arm64.Microsoft.NETCore.Runtime.Wasm.Binaryen.Transport , runtime.linux-musl-arm64.Microsoft.NETCore.Runtime.Wasm.Binaryen.Transport , runtime.linux-musl-x64.Microsoft.NETCore.Runtime.Wasm.Binaryen.Transport , runtime.linux-x64.Microsoft.NETCore.Runtime.Wasm.Binaryen.Transport , runtime.osx-arm64.Microsoft.NETCore.Runtime.Wasm.Binaryen.Transport , runtime.osx-x64.Microsoft.NETCore.Runtime.Wasm.Binaryen.Transport , runtime.win-arm64.Microsoft.NETCore.Runtime.Wasm.Binaryen.Transport , runtime.win-x64.Microsoft.NETCore.Runtime.Wasm.Binaryen.Transport
 From Version 9.0.0-alpha.1.24163.4 -> To Version 9.0.0-alpha.1.24168.2

* Update dependencies from https://github.com/dotnet/node build

runtime.linux-arm64.Microsoft.NETCore.Runtime.Wasm.Node.Transport , runtime.linux-musl-arm64.Microsoft.NETCore.Runtime.Wasm.Node.Transport , runtime.linux-musl-x64.Microsoft.NETCore.Runtime.Wasm.Node.Transport , runtime.linux-x64.Microsoft.NETCore.Runtime.Wasm.Node.Transport , runtime.osx-arm64.Microsoft.NETCore.Runtime.Wasm.Node.Transport , runtime.osx-x64.Microsoft.NETCore.Runtime.Wasm.Node.Transport , runtime.win-arm64.Microsoft.NETCore.Runtime.Wasm.Node.Transport , runtime.win-x64.Microsoft.NETCore.Runtime.Wasm.Node.Transport
 From Version 9.0.0-alpha.1.24161.1 -> To Version 9.0.0-alpha.1.24168.1

---------

Co-authored-by: dotnet-maestro[bot] <dotnet-maestro[bot]@users.noreply.github.com>
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.

4 participants