Skip to content

Commit

Permalink
zig-out changes - splits targets and optimizers level
Browse files Browse the repository at this point in the history
  • Loading branch information
kassane authored and microhobby committed Nov 8, 2023
1 parent d5a2015 commit ca62031
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 5 deletions.
2 changes: 1 addition & 1 deletion zigConsole/.vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"name": "Local AMD64",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/zig-out/bin/__change__",
"program": "${workspaceFolder}/zig-out/x86_64/Debug/bin/__change__",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceRoot}",
Expand Down
4 changes: 2 additions & 2 deletions zigConsole/.vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
"-P",
"${config:torizon_debug_ssh_port}",
"-pr",
"${workspaceFolder}/zig-out/bin",
"${workspaceFolder}/zig-out/aarch64/Debug/bin",
"${config:torizon_run_as}@${config:torizon_ip}:~/app"
],
"dependsOn": [
Expand Down Expand Up @@ -166,7 +166,7 @@
"-P",
"${config:torizon_debug_ssh_port}",
"-pr",
"${workspaceFolder}/zig-out/bin",
"${workspaceFolder}/zig-out/arm/Debug/bin",
"${config:torizon_run_as}@${config:torizon_ip}:~/app"
],
"dependsOn": [
Expand Down
11 changes: 10 additions & 1 deletion zigConsole/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,15 @@ RUN if [ "$IMAGE_ARCH" = "arm64" ] ; then \

# BUILD ------------------------------------------------------------------------

RUN mkdir -p target/deploy && \
if [ "$IMAGE_ARCH" = "arm64" ] ; then \
cp zig-out/aarch64/ReleaseSmall/bin/$APP_EXECUTABLE target/deploy ; \
elif [ "$IMAGE_ARCH" = "arm" ] ; then \
cp zig-out/arm/ReleaseSmall/bin/$APP_EXECUTABLE target/deploy ; \
elif [ "$IMAGE_ARCH" = "amd64" ] ; then \
cp zig-out/x86_64/ReleaseSmall/bin/$APP_EXECUTABLE target/deploy ; \
fi

# DEPLOY ------------------------------------------------------------------------
FROM --platform=linux/${IMAGE_ARCH} torizon/debian:${BASE_VERSION} AS Deploy

Expand All @@ -101,7 +110,7 @@ RUN apt-get -y update && apt-get install -y --no-install-recommends \
&& apt-get clean && apt-get autoremove && rm -rf /var/lib/apt/lists/*

# copy the build
COPY --from=Build /app/zig-out/bin/${APP_EXECUTABLE} /usr/bin/${APP_EXECUTABLE}
COPY --from=Build /app/target/deploy/${APP_EXECUTABLE} /usr/bin/${APP_EXECUTABLE}

# ADD YOUR ARGUMENTS HERE
CMD ${APP_EXECUTABLE}
Expand Down
26 changes: 26 additions & 0 deletions zigConsole/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,30 @@ pub fn build(b: *std.Build) void {

// copy binary from zig-cache to zig-out/bin [default]
b.installArtifact(binary);

// overwrite default output
b.resolveInstallPrefix(b.fmt("zig-out/{s}/{s}", .{ @tagName(target.getCpuArch()), @tagName(optimize) }), .{});

// This *creates* a Run step in the build graph, to be executed when another
// step is evaluated that depends on it. The next line below will establish
// such a dependency.
const run_cmd = b.addRunArtifact(binary);

// By making the run step depend on the install step, it will be run from the
// installation directory rather than directly from within the cache directory.
// This is not necessary, however, if the application depends on other installed
// files, this ensures they will be present and in the expected location.
run_cmd.step.dependOn(b.getInstallStep());

// This allows the user to pass arguments to the application in the build
// command itself, like this: `zig build run -- arg1 arg2 etc`
if (b.args) |args| {
run_cmd.addArgs(args);
}

// This creates a build step. It will be visible in the `zig build --help` menu,
// and can be selected like this: `zig build run`
// This will evaluate the `run` step rather than the default, which is "install".
const run_step = b.step("run", b.fmt("Run the {s} app", .{binary.name}));
run_step.dependOn(&run_cmd.step);
}
2 changes: 1 addition & 1 deletion zigConsole/src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub const std_options = struct {
pub const log_level = .info;
};
pub fn main() void {
log.info("Hello {s}!\n", .{"Torizon"});
log.info("Hello {s}!", .{"Torizon"});
// output:
// info(toradex): Hello Torizon!
}

0 comments on commit ca62031

Please sign in to comment.