Skip to content

Commit 572ea17

Browse files
committed
mos_buid.addExecutable now returns multiple steps
These can used to customize application building by the caller. 'addExecutable' should do the basics for building a MOS application, but it should be still be possible to add libraries, options specific to each application.
1 parent a79e221 commit 572ea17

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

src/apps/zapps/hello/build.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ pub fn build(b: *std.Build) !void {
99
.options = try mos.addDefaultOptions(b),
1010
.target = b.resolveTargetQuery(mos.i686_target_query),
1111
});
12-
b.getInstallStep().dependOn(exe);
12+
b.getInstallStep().dependOn(exe.root_step);
1313
}

src/apps/zapps/mos_build.zig

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,18 @@ pub const i686_target_query = Target.Query{
2424
.os_tag = .freestanding,
2525
};
2626

27-
const ExecutableOptions = struct {
27+
const DefaultBuildOptions = struct {
2828
options: BuildOptions,
2929
root_src_file: []const u8,
3030
target: Build.ResolvedTarget,
3131
optimize: std.builtin.OptimizeMode,
3232
};
3333

34+
const BuildSteps = struct {
35+
root_step: *Step,
36+
compilation_step: *Step.Compile,
37+
};
38+
3439
pub fn addDefaultOptions(b: *Build) !BuildOptions {
3540
const linker_script_path = b.option(
3641
[]const u8,
@@ -67,7 +72,7 @@ pub fn addDefaultOptions(b: *Build) !BuildOptions {
6772
};
6873
}
6974

70-
pub fn addExecutable(b: *Build, comptime name: []const u8, options: ExecutableOptions) *Step {
75+
pub fn addExecutable(b: *Build, comptime name: []const u8, options: DefaultBuildOptions) BuildSteps {
7176
// 1. Compilation and installation of the generated binary
7277
const exe = elf_compilation(b, name, &options);
7378
const exe_install = b.addInstallArtifact(exe, .{});
@@ -87,10 +92,14 @@ pub fn addExecutable(b: *Build, comptime name: []const u8, options: ExecutableOp
8792
// to build one particular target.
8893
const root = b.step(name, "Builds '" ++ name ++ "' target.");
8994
root.dependOn(&flatten_install.step);
90-
return root;
95+
96+
return .{
97+
.root_step = root,
98+
.compilation_step = exe,
99+
};
91100
}
92101

93-
fn elf_compilation(b: *Build, comptime name: []const u8, options: *const ExecutableOptions) *Step.Compile {
102+
fn elf_compilation(b: *Build, comptime name: []const u8, options: *const DefaultBuildOptions) *Step.Compile {
94103
const exe = b.addExecutable(.{
95104
.name = name,
96105
.root_module = b.createModule(.{

0 commit comments

Comments
 (0)