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
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 11 additions & 36 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,18 @@ on:
push:
pull_request:
branches: [ main ]
workflow_dispatch:

jobs:

Windows-WebUI:
runs-on: windows-latest
steps:
- uses: actions/checkout@v2
- uses: microsoft/[email protected]
- name: Windows-WebUI
shell: cmd
run: |
cd build\Windows\GCC
mingw32-make
cd ..\..\..
cd build\Windows\MSVC
call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat"
nmake

Linux-WebUI:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Linux-WebUI
run: |
cd build/Linux/GCC
make
cd ../../..
cd build/Linux/Clang
sudo ln -s llvm-ar-13 /usr/bin/llvm-ar
sudo ln -s llvm-ranlib-13 /usr/bin/llvm-ranlib
make

macOS-WebUI:
runs-on: macOS-latest
build:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v2
- name: macOS-WebUI
run: |
cd build/macOS/Clang
make
- uses: goto-bus-stop/setup-zig@v2
with:
version: 0.10.1
- name: Build WebUI
run: zig build --verbose
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ nul
# Zig
zig-cache/
zig-out/
build/

# macOS
.DS_Store
Expand Down
21 changes: 18 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,24 @@ Think of WebUI like a WebView controller, but instead of embedding the WebView c

## Build

- [Windows](https://github.com/alifcommunity/webui/tree/main/build/Windows)
- [Linux](https://github.com/alifcommunity/webui/tree/main/build/Linux)
- [macOS](https://github.com/alifcommunity/webui/tree/main/build/macOS)
To build WebUI you need to have [Zig](https://ziglang.org/) on your system. This allows for the simplification of compilation on different platforms and architectures without the need for complex toolchains or configurations. Below is a brief example on how to build WebUI. Execute the command from this project's root directory, and the output will be in the `build/` directory:

*Debug mode*
```
zig build -Ddebug
```

*Optimize for smaller artifact size*
```
zig build -Drelease-small
```

You can also cross-compile, or select different CPU architectures:

*Cross-Compile to a 64-bit arm linux platform*
```
zig build -Dtarget=aarch64-linux
```

## Examples

Expand Down
52 changes: 52 additions & 0 deletions build.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
const Builder = @import("std").build.Builder;
const Kind = @import("std").build.LibExeObjStep.SharedLibKind;

pub fn build(b: *Builder) void {
const target = b.standardTargetOptions(.{});
const mode = b.standardReleaseOptions();
const buildDir = "build";

// Build civetweb
const civetweb = b.addObject("civetweb", null);
civetweb.addIncludePath("include");
civetweb.setTarget(target);
civetweb.setBuildMode(mode);
civetweb.linkLibC();
civetweb.addCSourceFiles(&.{"src/civetweb/civetweb.c"}, &.{ "-DNDEBUG", "-DNO_CACHING", "-DNO_CGI", "-DNO_SSL", "-DUSE_WEBSOCKET", if (target.isWindows()) "-DMUST_IMPLEMENT_CLOCK_GETTIME" else "" });

// Build WebUI
const webui = b.addObject("webui", null);
webui.addIncludePath("include");
webui.setTarget(target);
webui.setBuildMode(mode);
webui.linkLibC();
webui.addCSourceFiles(&.{"src/webui.c"}, &.{if (mode == .Debug) "-DWEBUI_LOG" else ""});

// Create a static library
const static = b.addStaticLibrary("libwebui-2-static", null);
static.setTarget(target);
static.setBuildMode(mode);
static.addObject(civetweb);
static.addObject(webui);
static.setOutputDir(buildDir);
static.install();

// Create a shared library
const shared = b.addSharedLibrary(
"webui-2",
null,
Kind.unversioned,
);
shared.setTarget(target);
shared.setBuildMode(mode);
shared.addObject(civetweb);
shared.addObject(webui);
shared.setOutputDir(buildDir);
shared.strip = true;
webui.force_pic = true;
civetweb.force_pic = true;
if (target.isWindows()) {
shared.linkSystemLibrary("ws2_32");
}
shared.install();
}
45 changes: 0 additions & 45 deletions build/Linux/Clang/Makefile

This file was deleted.

Binary file removed build/Linux/Clang/libwebui-2-static-x64.a
Binary file not shown.
Binary file removed build/Linux/Clang/webui-2-x64.so
Binary file not shown.
45 changes: 0 additions & 45 deletions build/Linux/GCC/Makefile

This file was deleted.

Binary file removed build/Linux/GCC/libwebui-2-static-x64.a
Binary file not shown.
Binary file removed build/Linux/GCC/webui-2-x64.so
Binary file not shown.
15 changes: 0 additions & 15 deletions build/Linux/README.md

This file was deleted.

27 changes: 0 additions & 27 deletions build/README.md

This file was deleted.

47 changes: 0 additions & 47 deletions build/Windows/GCC/Makefile

This file was deleted.

Binary file removed build/Windows/GCC/libwebui-2-static-x64.a
Binary file not shown.
Binary file removed build/Windows/GCC/webui-2-x64.dll
Binary file not shown.
45 changes: 0 additions & 45 deletions build/Windows/MSVC/Makefile

This file was deleted.

Binary file removed build/Windows/MSVC/webui-2-static-x64.lib
Binary file not shown.
Binary file removed build/Windows/MSVC/webui-2-x64.dll
Binary file not shown.
Binary file removed build/Windows/MSVC/webui-2-x64.lib
Binary file not shown.
23 changes: 0 additions & 23 deletions build/Windows/README.md

This file was deleted.

Loading