webui
webui copied to clipboard
Simplifying the build process by using Zig's toolchain
Problem statement: The current build process seems quite repetitive and requires different compiler toolchains per platform, making it quite a difficult task to maintain the build process. I also don't think that we should be including the built artifacts in the source code, as this is something that can be provided as artifacts when creating releases.
Proposal: Here I'm introducing Zig as a build system that allows us to have a single (and simple) build file and build the appropriate artifacts regardless of platform. By utilizing this approach we make it quite trivial to maintain the build process of this library. I have also updated the Github workflow action to utilize this build system to build on the three major platforms. In addition, my next task is to simplify the process of building the examples, which also suffers from the problem statement.
The draft status of this PR is such that I can have something for you to have a look while I continue working on migrating and simplifying all examples to also use Zig.
Thank you! 🎉
You can find the successful run of the new build system in the Github actions here: https://github.com/xD0135/webui/actions/runs/4889436581
Thank you very much for the suggestion and this simplified build script 😃👍 But, making the only way to build WebUI from source is by installing Zig won't work for some people. This is because Zig is fantastic and a Rust competitor, but Zig is still new, and only some have Zig on their machine.
We have a makefile
for every compiler on every OS. Each one is different. Deppent on the end-user needs.
I suggest keeping everything the same but adding additional build scripts, like Zig, CMake, and Ninja scripts.
Adding:
Zig: build/build.zig
CMake: build/CMakeLists.txt
Ninja: build/build.ninja
Those build scripts should do what those scripts do:
build/windows_build.bat
build/linux_build.sh
build/macos_build.sh
Let's start with build/build.zig
first 🐱👤
Thank you for your reply. Regarding:
But, making the only way to build WebUI from source is by installing Zig won't work for some people.
This could be said regarding the current model as well 😁, but unlike the current model, getting a compiler toolchain installed in Windows for example is not a straightforward process (where installing Zig is relatively small and self-contained), and it's impossible to cross-compile with the current toolchain, which as a developer building my application with WebUI is something that I want to be able to easily do.
This is because Zig is fantastic and a Rust competitor, but Zig is still new, and only some have Zig on their machine.
This statement is not completely accurate. From purely a language perspective, perhaps they compete, but unlike Rust, Zig is also a self-contained compiler/toolchain build system. Here's a wonderful article on Uber's decision to use Zig's toolchain to power their infrastructure.
We have a makefile for every compiler on every OS. Each one is different.
Exactly! This is the exact problem that I'm proposing that we fix by using Zig's toolchain.
I suggest keeping everything the same but adding additional build scripts, like Zig, CMake, and Ninja scripts.
IMO this only introduces more complexities and dependencies instead of simplifying and removing them, and defaulting to a single and powerful build system that is also able to cross-compile.
Before dismissing my proposal, I highly encourage you to take some time to learn about Zig purely from a build system/toolchain perspective and not as a language competitor to other languages. I'm including a couple of interesting links below:
- https://andrewkelley.me/post/zig-cc-powerful-drop-in-replacement-gcc-clang.html
- https://zig.news/kristoff/compile-a-c-c-project-with-zig-368j
- https://www.uber.com/en-BR/blog/bootstrapping-ubers-infrastructure-on-arm64-with-zig
- https://ziglang.org/learn/overview/#cross-compiling-is-a-first-class-use-case
I liked this article Cross-compile a C/C++ Project with Zig.
Please, from this list, what Zig can do? I know Zig can't do all of it, but I'm new to the Zig toolchains, and I would like to know the Zig capabilities.
x86-64Bit
- Build WebUI for Microsoft Visual Studio Projects on Windows (MSVC ABI Compatibilities) ->
/Release/Windows/x86_64/MSVC
- Build WebUI for MinGW Projects on Windows (GCC ABI Compatibilities) ->
/Release/Windows/x86_64/GCC
- Build WebUI for TCC Projects on Windows (GCC ABI Compatibilities) ->
/Release/Windows/x86_64/TCC
- Build WebUI for GCC Projects on Linux (GCC ABI Compatibilities) ->
/Release/Linux/x86_64/GCC
- Build WebUI for Clang Projects on Linux (Clang ABI Compatibilities (Not GCC ABI)) ->
/Release/Linux/x86_64/Clang
- Build WebUI for Clang Projects on macOS (Clang ABI Compatibilities) ->
/Release/macOS/x86_64/Clang
ARM-64Bit
- Build WebUI for Microsoft Visual Studio Projects on Windows (MSVC ABI Compatibilities) ->
/Release/Windows/ARM64/MSVC
- Build WebUI for MinGW Projects on Windows (GCC ABI Compatibilities) ->
/Release/Windows/ARM64/GCC
- Build WebUI for TCC Projects on Windows (GCC ABI Compatibilities) ->
/Release/Windows/ARM64/TCC
- Build WebUI for GCC Projects on Linux (GCC ABI Compatibilities) ->
/Release/Linux/ARM64/GCC
- Build WebUI for Clang Projects on Linux (Clang ABI Compatibilities (Not GCC ABI)) ->
/Release/Linux/ARM64/Clang
- Build WebUI for Clang Projects on macOS (Clang ABI Compatibilities) ->
/Release/macOS/ARM64/Clang
Let's say we run the Zing build toolchain from an x86 64Bit Windows
. And all x86 64Bit MSVC
, GCC
and TCC
are installed. So what can cross-compiling Zig do?
Please, from this list, what Zig can do? I know Zig can't do all of it, but I'm new to the Zig toolchains, and I would like to know the Zig capabilities
The links I included previously provide an in-depth list of all of its capabilities. Please take a moment to review them.
Let's say we run the Zing build toolchain from an x86 64Bit Windows. And all x86 64Bit MSVC, GCC and TCC are installed. So what can cross-compiling Zig do?
Cross-compilation means being able to compile across platform architectures and OS, and not cross-compile between the compilers you have listed. For example, in Windows I could run the following command and build WebUI for ARM Linux:
zig build -Dtarget=aarch64-linux
In the same machine, Zig would remove the need to use any of those listed compilers, as it is a compiler itself.
Any additional thoughts on this proposal? If you're not ready for it I'll close the PR and maintain my own fork, as I do need this simpler build system. Thanks
First of all, thank you for the suggestion. I really appreciate it. The Zig build tools is a great system to use. And many people needs it. But others may need CMake or a simple make file.
My suggestion is to add the Zig script and keep the old script as well to support different needs.
The build process was simplified and some of the mentioned problems were solved since the PR was opened.
As it works on old code, maybe we can close this as superseded. And re-submit or re-open when it is finished over the current code base.
Let's keep it as a draft for now, if we close it we will forget about it!