Repository navigation
Expand file tree
/
Copy pathbuild.zig
More file actions
47 lines (43 loc) · 2.44 KB
/
Copy pathbuild.zig
File metadata and controls
47 lines (43 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//! The Google Drive plugin for fizzy — a third-party plugin in the canonical shape: depend on
//! the fizzy SDK, call `fizzy.plugin.create` + `.install`. `zig build` produces
//! `drive.<dylib|dll|so>`; `zig build test` runs the Drive client and OAuth tests.
const std = @import("std");
const fizzy = @import("fizzy");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
ensureCredentials(b);
const plugin = fizzy.plugin.create(b, .{ .target = target, .optimize = optimize });
if (b.lazyDependency("icons", .{ .target = target, .optimize = optimize })) |dep| {
plugin.module.addImport("icons", dep.module("icons"));
}
fizzy.plugin.install(b, plugin.lib, .{});
// The plugin module carries the tests that need `core` (the Drive client over a scripted
// transport) and the pure ones (OAuth pieces) alike.
const test_step = b.step("test", "Run the Drive client and OAuth tests");
const tests = b.addTest(.{ .name = "drive-tests", .root_module = plugin.module });
test_step.dependOn(&b.addRunArtifact(tests).step);
}
/// `credentials.zon` is `@import`ed by `plugin.zig`, so it has to exist. A developer copies
/// `credentials.zon.example`; CI has none, so it is written from the environment — empty
/// strings when those are unset too, which builds a plugin that can only say "not configured".
fn ensureCredentials(b: *std.Build) void {
const io = b.graph.io;
if (b.build_root.handle.access(io, "credentials.zon", .{})) |_| return else |_| {}
const id = b.graph.environ_map.get("FIZZY_DRIVE_CLIENT_ID") orelse "";
const secret = b.graph.environ_map.get("FIZZY_DRIVE_CLIENT_SECRET") orelse "";
const web_id = b.graph.environ_map.get("FIZZY_DRIVE_WEB_CLIENT_ID") orelse "";
const text = b.fmt(
\\// Generated by `zig build` from the environment (see credentials.zon.example). Not committed.
\\.{{
\\ .client_id = "{s}",
\\ .client_secret = "{s}",
\\ .web_client_id = "{s}",
\\}}
\\
, .{ id, secret, web_id });
b.build_root.handle.writeFile(io, .{ .sub_path = "credentials.zon", .data = text }) catch |err| {
std.debug.panic("drive: could not write credentials.zon: {t}", .{err});
};
if (id.len == 0) std.debug.print("drive: no credentials.zon and FIZZY_DRIVE_CLIENT_ID unset — the plugin will refuse to sign in until one is provided\n", .{});
}