Skip to content
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

Simplifying the build process by using Zig's toolchain #94

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

xD0135
Copy link

@xD0135 xD0135 commented May 5, 2023

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! 🎉

@xD0135
Copy link
Author

xD0135 commented May 5, 2023

You can find the successful run of the new build system in the Github actions here:
https://github.com/xD0135/webui/actions/runs/4889436581

@AlbertShown
Copy link
Contributor

AlbertShown commented May 5, 2023

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 🐱‍👤

@xD0135
Copy link
Author

xD0135 commented May 5, 2023

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:

@xD0135 xD0135 changed the title Simplifying the build process by using Zig Simplifying the build process by using Zig toolchain May 5, 2023
@xD0135 xD0135 changed the title Simplifying the build process by using Zig toolchain Simplifying the build process by using Zig's toolchain May 5, 2023
@AlbertShown
Copy link
Contributor

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

  1. Build WebUI for Microsoft Visual Studio Projects on Windows (MSVC ABI Compatibilities) -> /Release/Windows/x86_64/MSVC
  2. Build WebUI for MinGW Projects on Windows (GCC ABI Compatibilities) -> /Release/Windows/x86_64/GCC
  3. Build WebUI for TCC Projects on Windows (GCC ABI Compatibilities) -> /Release/Windows/x86_64/TCC
  4. Build WebUI for GCC Projects on Linux (GCC ABI Compatibilities) -> /Release/Linux/x86_64/GCC
  5. Build WebUI for Clang Projects on Linux (Clang ABI Compatibilities (Not GCC ABI)) -> /Release/Linux/x86_64/Clang
  6. Build WebUI for Clang Projects on macOS (Clang ABI Compatibilities) -> /Release/macOS/x86_64/Clang

ARM-64Bit

  1. Build WebUI for Microsoft Visual Studio Projects on Windows (MSVC ABI Compatibilities) -> /Release/Windows/ARM64/MSVC
  2. Build WebUI for MinGW Projects on Windows (GCC ABI Compatibilities) -> /Release/Windows/ARM64/GCC
  3. Build WebUI for TCC Projects on Windows (GCC ABI Compatibilities) -> /Release/Windows/ARM64/TCC
  4. Build WebUI for GCC Projects on Linux (GCC ABI Compatibilities) -> /Release/Linux/ARM64/GCC
  5. Build WebUI for Clang Projects on Linux (Clang ABI Compatibilities (Not GCC ABI)) -> /Release/Linux/ARM64/Clang
  6. Build WebUI for Clang Projects on macOS (Clang ABI Compatibilities) -> /Release/macOS/ARM64/Clang

@AlbertShown
Copy link
Contributor

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?

@xD0135
Copy link
Author

xD0135 commented May 5, 2023

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.

@xD0135
Copy link
Author

xD0135 commented May 12, 2023

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

@hassandraga
Copy link
Member

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.

@ttytm
Copy link
Member

ttytm commented Oct 3, 2023

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.

@hassandraga
Copy link
Member

Let's keep it as a draft for now, if we close it we will forget about it!

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.

None yet

4 participants