Skip to content

Commit

Permalink
Merge pull request #9 from kassane/update
Browse files Browse the repository at this point in the history
refactoring `build.zig` and CI to new commands
  • Loading branch information
kassane authored May 13, 2023
2 parents 9380e5c + 25dcf4f commit 0be3b6d
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 49 deletions.
19 changes: 5 additions & 14 deletions .github/workflows/Linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,11 @@ jobs:
- name: Install buildtools
run: |
sudo apt update
sudo apt install -f build-essential libdouble-conversion-dev \
libgl1-mesa-dev libxkbcommon-x11-0 libpulse-dev libxext-dev \
libdrm-dev libx11-dev libudev-dev libinput-dev libts-dev libxcb-xinerama0-dev \
libxcb-xinerama0 libxkbcommon-dev libxkbcommon-x11-dev libx11-dev libxcb1-dev \
libx11-xcb-dev libxext-dev cmake -y
- name: Install Qt5
uses: jurplel/install-qt-action@v2
with:
version: 5.15.2
modules: qtcharts
dir: '${{ github.workspace }}/build/'
sudo apt install build-essential qtbase5-dev qtbase5-private-dev \
qtdeclarative5-dev qtquickcontrols2-5-dev qml-module-qtquick2 \
qml-module-qtquick-controls2 qml-module-qtquick-window2 cmake -y
- name: Build & Tests
run: |
QTDIR="$GITHUB_WORKSPACE/build/Qt/5.15.2/gcc_64" && PATH="${QTDIR}/bin:$PATH" && LDFLAGS=-L${QTDIR}/lib && CPPFLAGS=-I${QTDIR}/include;
zig build -Doptimize=ReleaseSafe && ls zig-out/bin
zig build cmake
zig build -fsummary -freference-trace
8 changes: 4 additions & 4 deletions .github/workflows/MSYS.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ jobs:
if: ${{ matrix.arch == 'i686' }}
run: |
cd /C/_
zig build -Doptimize=ReleaseSafe -Dtarget=x86-windows-gnu
zig build cmake
zig build -Dtarget=x86-windows -fsummary -freference-trace
- name: Build & Tests (x86_x64)
shell: msys2 {0}
if: ${{ matrix.arch == 'x86_64' }}
run: |
cd /C/_
export CC=gcc
export CXX=g++
zig build -Doptimize=ReleaseSafe -Dtarget=x86_64-windows-gnu
zig build cmake
zig build -Dtarget=x86_64-windows -fsummary -freference-trace
5 changes: 3 additions & 2 deletions .github/workflows/MacOS.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
run: brew install cmake

- name: Install Qt
uses: jurplel/install-qt-action@v2
uses: jurplel/install-qt-action@v3
with:
version: 5.15.2
dir: '${{ github.workspace }}/build/'
Expand All @@ -28,4 +28,5 @@ jobs:
QTDIR="$GITHUB_WORKSPACE/build/Qt/5.15.2/clang_64" && \
PATH="${QTDIR}/bin:$PATH" && LDFLAGS=-L${QTDIR}/lib && \
CPPFLAGS=-I${QTDIR}/include && \
zig build -Doptimize=ReleaseSafe && ls zig-out/bin
zig build cmake && \
zig build -fsummary -freference-trace
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ All software required for building.
- Zig v0.11.0 or higher
- CMake v3.2 or higher (DOtherSide build)

### Question

#### Works on Qt6?

Maybe, check [DOtherSide](https://github.com/filcuc/dotherside) support!!

## Instructions

~~~bash
Expand All @@ -25,8 +31,11 @@ git clone --recursive https://github.com/kassane/qml_zig
# Open folder
cd qml_zig

# build DOtherSide
zig build cmake

# Build
zig build ExampleName -Drelease-safe|-Drelease-fast|-Drelease-small
zig build ExampleName -Doptimize=ReleaseSafe|-Doptimize=ReleaseFast|-Doptimize=ReleaseSmall
~~~

# Examples
Expand Down
99 changes: 71 additions & 28 deletions build.zig
Original file line number Diff line number Diff line change
@@ -1,43 +1,74 @@
const std = @import("std");
const Builder = std.Build.Builder;
const Pkg = std.build.Pkg;
const string = []const u8;
const fmt_description = "Run the {s} example";

pub fn build(b: *Builder) !void {
pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const mode = b.standardOptimizeOption(.{});

// Note: If it is not necessary to compile DOtherSide library, please comment on this line.
try cmakeBuild(b);
const cmake = cmakeBuild(b);
const cmake_step = b.step("cmake", "Run cmake build");
cmake_step.dependOn(&cmake.step);

// Original examples
try makeExample(b, mode, target, "examples/animated.zig", "Animated");
try makeExample(b, mode, target, "examples/hello.zig", "Hello");
try makeExample(b, .{
.optimize = mode,
.target = target,
.path = "examples/animated.zig",
});
try makeExample(b, .{
.optimize = mode,
.target = target,
.path = "examples/hello.zig",
});

// More examples
try makeExample(b, mode, target, "examples/button.zig", "Button");
try makeExample(b, .{
.optimize = mode,
.target = target,
.path = "examples/button.zig",
});

// Copypasta from the Go QML eamples https://github.com/go-qml/qml/tree/v1/examples
try makeExample(b, mode, target, "examples/particle.zig", "Particle");
try makeExample(b, mode, target, "examples/layouts.zig", "Layouts");
try makeExample(b, mode, target, "examples/splitview.zig", "Splits");
try makeExample(b, mode, target, "examples/tableview.zig", "Tables");
try makeExample(b, .{
.optimize = mode,
.target = target,
.path = "examples/particle.zig",
});
try makeExample(b, .{
.optimize = mode,
.target = target,
.path = "examples/layouts.zig",
});
try makeExample(b, .{
.optimize = mode,
.target = target,
.path = "examples/splitview.zig",
});
try makeExample(b, .{
.optimize = mode,
.target = target,
.path = "examples/tableview.zig",
});

// Cloned simple examples from the Qml doco
try makeExample(b, mode, target, "examples/cells.zig", "Cells");
try makeExample(b, .{
.optimize = mode,
.target = target,
.path = "examples/cells.zig",
});
}

fn makeExample(b: *Builder, mode: std.builtin.Mode, target: std.zig.CrossTarget, src: string, name: string) !void {
fn makeExample(b: *std.Build, src: BuildInfo) !void {
const example = b.addExecutable(.{
.name = name,
.root_source_file = .{ .path = src },
.optimize = mode,
.target = target,
.name = src.filename(),
.root_source_file = .{ .path = src.path },
.optimize = src.optimize,
.target = src.target,
});

//Strip file
if (mode != .Debug) {
if (src.optimize != .Debug) {
example.strip = true;
}

Expand All @@ -51,28 +82,29 @@ fn makeExample(b: *Builder, mode: std.builtin.Mode, target: std.zig.CrossTarget,

example.linkSystemLibraryName("DOtherSide");
example.linkLibC();
example.install();

const run_cmd = example.run();
b.installArtifact(example);

const run_cmd = b.addRunArtifact(example);
run_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| {
run_cmd.addArgs(args);
}

var descr = b.fmt(fmt_description, .{name});
const run_step = b.step(name, descr);
var descr = b.fmt("Run the {s} example", .{src.filename()});
const run_step = b.step(src.filename(), descr);
run_step.dependOn(&run_cmd.step);
}

fn cmakeBuild(b: *Builder) !void {
fn cmakeBuild(b: *std.Build) *std.Build.Step.Run {
//CMake builds - DOtherSide build
const DOtherSide_configure = b.addSystemCommand(&[_][]const u8{
"cmake",
"-B",
"zig-cache",
"-S",
"deps/dotherside",
"-DCMAKE_BUILD_TYPE=Release",
"-DCMAKE_BUILD_TYPE=RelMinSize",
});
const DOtherSide_build = b.addSystemCommand(&[_][]const u8{
"cmake",
Expand All @@ -81,6 +113,17 @@ fn cmakeBuild(b: *Builder) !void {
"--parallel",
});

try DOtherSide_configure.step.make();
try DOtherSide_build.step.make();
}
DOtherSide_build.step.dependOn(&DOtherSide_configure.step);
return DOtherSide_build;
}

const BuildInfo = struct {
path: string,
target: std.zig.CrossTarget,
optimize: std.builtin.OptimizeMode,

fn filename(self: BuildInfo) []const u8 {
var split = std.mem.split(u8, std.fs.path.basename(self.path), ".");
return split.first();
}
};

0 comments on commit 0be3b6d

Please sign in to comment.