Changes
2 changed files (+118/-18)
-
gtk/.gitignore (deleted)
-
@@ -1,18 +0,0 @@# Copyright 2025 Shota FUJI # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # # SPDX-License-Identifier: Apache-2.0 # What: Built executable binary. /Application
-
-
gtk/build.zig (new)
-
@@ -0,0 +1,118 @@// Copyright 2025 Shota FUJI // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 //! This file defines how `zig build` command behaves. //! Run `zig build --help` for available subcommands and options. //! //! Learn more at //! https://ziglang.org/learn/build-system/ const std = @import("std"); const BuildError = error{ NonValaSourceInSourceListError, }; pub fn build(b: *std.Build) !void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); // Vala source codes to compile. As Vala does not have module system, // we have to list every source code files to include. const vala_sources = [_][]const u8{ "src/Application.vala", }; // System libraries to link. // Each library must be provided by packages listed in `plugin.json` (devbox package), // so anyone can build without manually installing system libraries. const system_libraries = [_][]const u8{ "gtk4", }; // A directory containing C source files compiled from Vala source code. // If you use this LazyPath in your artifact, the artifact automatically depends on // this Vala to C complication step. You don't have to manually `a.dependOn()`. const vala_cdir = vala: { const valac = b.addSystemCommand(&.{"valac"}); // Tell Vala compiler to emit C rather than compile using system C compiler. valac.addArg("--ccode"); // Tell Vala what system libraries to use. Perhaps type checking things? for (system_libraries) |lib| { valac.addArgs(&.{ "--pkg", lib }); } // Tell Vala to emit C source files under the output directory. // The directory usually is Zig cache directory (like ".zig-cache/o/xxx"). // For example, when there is "src/Foo.vala", this step produces // ".zig-cache/o/hash-or-something-idk/vala/src/Foo.c" valac.addArg("--directory"); const dir = valac.addOutputDirectoryArg("vala"); // Vala compiler takes a list of Vala source files, then process them all. for (vala_sources) |src| { valac.addFileArg(b.path(src)); } break :vala dir; }; // An executable. const exe = exe: { const exe = b.addExecutable(.{ .name = "plac", .target = target, .optimize = optimize, }); // This is a standard C application, so libc is required. exe.linkLibC(); // Vala does not bundle system libraries (of course): we have to tell the // linker. for (system_libraries) |lib| { exe.linkSystemLibrary(lib); } // At this point, build does not run yet—we can't enumerate C source // directory. Since we already have a list of Vala source code, we can // build a list of paths of to-be-generated C source file. for (vala_sources) |src| { // Basically unreachable. Don't put non Vala source into `vala_sources`. if (!std.mem.endsWith(u8, src, ".vala")) { return BuildError.NonValaSourceInSourceListError; } // Looks fragile but it works. Even if it produced incorrect paths, // filesystem and Zig compiler will tell us a file is missing. const rel_path = b.fmt("{s}.c", .{src[0..(src.len - 5)]}); // src = "src/Foo.vala" // rel_path = "src/Foo.c" // file = "(step cache directory)/vala/src/Foo.c" exe.addCSourceFile(.{ .file = try vala_cdir.join(b.allocator, rel_path), }); } break :exe exe; }; // Install a main executable file on "zig build" without subcommand. b.installArtifact(exe); }
-