//demo 3.2
conststd=@import("std");pubfnbuild(b:*std.Build)void{consttarget=b.standardTargetOptions(.{});constoptimize=b.standardOptimizeOption(.{});constexe=b.addExecutable(.{.name="example",.root_source_file=.{.path="main.zig"},.target=target,.optimize=optimize,});exe.linkLibC();exe.linkSystemLibrary("curl");b.installArtifact(exe);construn_cmd=b.addRunArtifact(exe);run_cmd.step.dependOn(b.getInstallStep());if(b.args)|args|{run_cmd.addArgs(args);}construn_step=b.step("run","Run the app");run_step.dependOn(&run_cmd.step);}
// 示例片段
conststd=@import("std");pubfnbuild(b:*std.build.Builder)void{consttarget=b.standardTargetOptions(.{});constoptimize=b.standardOptimizeOption(.{});constgame=b.addExecutable(.{.name="game",.root_source_file=.{.path="src/game.zig"},.target=target,.optimize=optimize,});b.installArtifact(game);constpack_tool=b.addExecutable(.{.name="pack",.root_source_file=.{.path="tools/pack.zig"},.target=target,.optimize=optimize,});//译者改动:const precompilation = pack_tool.run(); // returns *RunStep
constprecompilation=b.addRunArtifact(pack_tool);precompilation.addArtifactArg(game);precompilation.addArg("assets.zip");constpack_step=b.step("pack","Packs the game and assets together");pack_step.dependOn(&precompilation.step);}
// 示例片段
conststd=@import("std");pubfnbuild(b:*std.build.Builder)void{constmode=b.standardOptimizeOption(.{});// const mode = b.standardReleaseOptions();
consttarget=b.standardTargetOptions(.{});// Generates the lex-based parser
constparser_gen=b.addSystemCommand(&[_][]constu8{"flex","--outfile=review-parser.c","review-parser.l",});// Our application
constexe=b.addExecutable(.{.name="upload-review",.root_source_file=.{.path="src/main.zig"},.target=target,.optimize=mode,});{exe.step.dependOn(&parser_gen.step);exe.addCSourceFile(.{.file=std.build.LazyPath.relative("review-parser.c"),.flags=&.{}});// add zig-args to parse arguments
constap=b.createModule(.{.source_file=.{.path="vendor/zig-args/args.zig"},.dependencies=&.{},});exe.addModule("args-parser",ap);// add libcurl for uploading
exe.addIncludePath(std.build.LazyPath.relative("vendor/libcurl/include"));exe.addObjectFile(std.build.LazyPath.relative("vendor/libcurl/lib/libcurl.a"));exe.linkLibC();b.installArtifact(exe);// exe.install();
}// Our test suite
consttest_step=b.step("test","Runs the test suite");consttest_suite=b.addTest(.{.root_source_file=.{.path="src/tests.zig"},});test_suite.step.dependOn(&parser_gen.step);exe.addCSourceFile(.{.file=std.build.LazyPath.relative("review-parser.c"),.flags=&.{}});// add libcurl for uploading
exe.addIncludePath(std.build.LazyPath.relative("vendor/libcurl/include"));exe.addObjectFile(std.build.LazyPath.relative("vendor/libcurl/lib/libcurl.a"));test_suite.linkLibC();test_step.dependOn(&test_suite.step);{constdeploy_step=b.step("deploy","Creates an application bundle");// compile the app bundler
constdeploy_tool=b.addExecutable(.{.name="deploy",.root_source_file=.{.path="tools/deploy.zig"},.target=target,.optimize=mode,});{deploy_tool.linkLibC();deploy_tool.linkSystemLibrary("libzip");}constbundle_app=b.addRunArtifact(deploy_tool);bundle_app.addArg("app-bundle.zip");bundle_app.addArtifactArg(exe);bundle_app.addArg("resources/index.htm");bundle_app.addArg("resources/style.css");deploy_step.dependOn(&bundle_app.step);}}