Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for dependent packages when using build.zig #4343

Merged
merged 1 commit into from
Feb 2, 2020

Conversation

frmdstryr
Copy link
Contributor

For #855

Example build.zig

const Builder = @import("std").build.Builder;
const Package = @import("std").build.Pkg;
const builtin = @import("builtin");


pub fn build(b: *Builder) void {
    // Cortex-M7 uses armv7em
    const arch = builtin.Arch{ .thumb = .v7em };
    const cpu = &builtin.Target.arm.cpu.cortex_m7;

    const mode = b.standardReleaseOptions();
    const elf = b.addExecutable("firmware.elf", "startup.zig");
    elf.setTheTarget(builtin.Target{
        .Cross = .{
            .arch = arch,
            .os = .freestanding,
            .abi = .none,
            .cpu_features = builtin.Target.CpuFeatures.initFromCpu(arch, cpu),
        },
    });

    const stm32 = Package{
        .name="stm32",
        .path="../../lib/stm32/index.zig"
    };
    elf.addPackage(stm32);
    elf.addPackage(Package{
        .name="gfx",
        .path="../../lib/gfx/tft.zig",
        .dependencies=&[_]Package{stm32},
    });

    elf.setBuildMode(mode);
    elf.setLinkerScriptPath("stm32h743xi.ld");
    elf.setOutputDir(b.build_root); // always build in same dir as build.zig
    elf.single_threaded = true;

    const gdb = b.addSystemCommand(&[_][]const u8{"arm-none-eabi-gdb"});
    gdb.addArtifactArg(elf);
    b.step("run", "Run with gdb").dependOn(&gdb.step);

    b.default_step.dependOn(&elf.step);
    b.installArtifact(elf);
}

@daurnimator daurnimator added the zig build system std.Build, the build runner, `zig build` subcommand, package management label Feb 2, 2020
@daurnimator
Copy link
Collaborator

        .path="../../lib/gfx/tft.zig",

I think we should point at the package's build.zig

And perhaps that means that build.zig needs to have some public function to prepare its own build options?

@andrewrk
Copy link
Member

andrewrk commented Feb 2, 2020

And perhaps that means that build.zig needs to have some public function to prepare its own build options?

See #353. That's part of a larger effort towards a package manager. This pull request is more exposing CLI options to the build script.

@andrewrk andrewrk merged commit 32291ab into ziglang:master Feb 2, 2020
@andrewrk
Copy link
Member

andrewrk commented Feb 2, 2020

Thanks @frmdstryr

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
zig build system std.Build, the build runner, `zig build` subcommand, package management
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants