srctree

blame
build.zig
const std = @import("std"); pub fn build(b: *std.Build) void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); const dep_optimize = b.option(std.builtin.OptimizeMode, "dep-optimize", "optimization mode of most dependencies") orelse .ReleaseFast; const wasm_target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding, .cpu_features_add = std.Target.wasm.featureSet(&.{ .atomics, .bulk_memory, // .extended_const, not supported by Safari .multivalue, .mutable_globals, .nontrapping_fptoint, .reference_types, //.relaxed_simd, not supported by Firefox or Safari .sign_ext, // observed to cause Error occured during wast conversion : // Unknown operator: 0xfd058 in Firefox 117 //.simd128, // .tail_call, not supported by Safari }), }); const wasm_optimize = switch (optimize) { .Debug => optimize, else => .ReleaseSmall, }; const ffmpeg_dep = b.dependency("ffmpeg", .{ .target = target, .optimize = dep_optimize, }); const python_dep = b.dependency("cpython", .{ .target = target, .optimize = dep_optimize, }); const soundio_dep = b.dependency("soundio", .{ .target = target, // I encountered undefined behavior in the pulseaudio C library code. // If this is Debug or ReleaseSafe it gets triggered. .optimize = dep_optimize, }); const libsoundio = soundio_dep.artifact("soundio"); const twi_mod = b.addModule("Twi", .{ .root_source_file = b.path("Twi/Twi.zig"), .target = target, .optimize = optimize, }); const player = b.addModule("player", .{ .root_source_file = b.path("player/root.zig"), .target = target, .optimize = optimize, .imports = &.{ .{ .name = "Twi", .module = twi_mod }, }, }); const shared_server = b.addModule("shared", .{ .root_source_file = b.path("shared/root.zig"), .target = target, .optimize = optimize, .imports = &.{ .{ .name = "Twi", .module = twi_mod }, }, }); const shared_wasm = b.addModule("shared", .{ .root_source_file = b.path("shared/root.zig"), .target = wasm_target, .optimize = wasm_optimize, .imports = &.{ .{ .name = "Twi", .module = twi_mod }, }, }); player.addImport("av", ffmpeg_dep.module("av")); player.addImport("SoundIo", soundio_dep.module("SoundIo")); player.linkLibrary(libsoundio); const playlist = b.addExecutable(.{ .name = "playlist", .root_source_file = b.path("example/playlist.zig"), .target = target, .optimize = optimize, }); playlist.root_module.addImport("player", player); installBin(b, playlist); const analyze = b.addExecutable(.{ .name = "analyze", .root_source_file = b.path("example/analyze.zig"), .target = target, .optimize = optimize, }); analyze.root_module.addImport("player", player); installBin(b, analyze); const fingerprint = b.addExecutable(.{ .name = "fingerprint", .root_source_file = b.path("example/fingerprint.zig"), .target = target, .optimize = optimize, }); fingerprint.root_module.addImport("player", player); installBin(b, fingerprint); const groovebasin = b.addExecutable(.{ .name = "groovebasin", .root_source_file = b.path("server/main.zig"), .target = target, .optimize = optimize, }); groovebasin.root_module.addImport("player", player); groovebasin.root_module.addImport("shared", shared_server); groovebasin.root_module.addImport("StaticHttpFileServer", b.dependency("StaticHttpFileServer", .{ .optimize = optimize, .target = target, }).module("StaticHttpFileServer")); installBin(b, groovebasin); b.getInstallStep().dependOn(&b.addInstallArtifact(python_dep.artifact("cpython"), .{ .dest_dir = .{ .override = .{ .custom = "python" } }, }).step); b.installDirectory(.{ .source_dir = python_dep.path("Lib"), .install_dir = .prefix, .install_subdir = "python/Lib", }); b.installDirectory(.{ .source_dir = b.path("www"), .install_dir = .prefix, .install_subdir = "www", }); const wasm = b.addExecutable(.{ .name = "main", .root_source_file = .{ .path = "client/main.zig" }, .target = wasm_target, .optimize = wasm_optimize, }); wasm.root_module.addImport("shared", shared_wasm); wasm.rdynamic = true; // expose exported functions to wasm wasm.entry = .disabled; b.getInstallStep().dependOn(&b.addInstallFile(wasm.getEmittedBin(), "www/main.wasm").step); const unit_tests = b.addTest(.{ .root_source_file = b.path("server/main.zig"), .target = target, .optimize = optimize, }); const run_unit_tests = b.addRunArtifact(unit_tests); const test_step = b.step("test", "Run unit tests"); test_step.dependOn(&run_unit_tests.step); } fn installBin(b: *std.Build, bin: *std.Build.Step.Compile) void { b.getInstallStep().dependOn(&b.addInstallArtifact(bin, .{ .dest_dir = .{ .override = .prefix }, }).step); }