why
tl;dr.
I’m trying to use zig to build my work repo. We just switched vms and our glibc jumped forward, but there is still older glibc out there so being able to target it would be great.
what
We do this thing where we place our git information into the binary. So I need to run system commands.
Current build system uses some shell to generate those object files. I’m trying to port with zig.
e.g.
# capture working branch
branch=$(git branch | grep \* | cut -d ' ' -f2)
echo -e "branch:\t\t$branch"
rm -f GIT_BRANCH
echo "$branch" >> GIT_BRANCH
objcopy --input binary \
--output-target elf64-x86-64 \
--binary-architecture i386 GIT_BRANCH git_branch.o
The following is what I have.
// I HATE THIS BTW (JUD)
// OBJECTS += version.o git_build.o git_commit.o git_tag.o
const branch = b.addSystemCommand(
&[_][]const u8{
"git",
"rev-parse",
"--abbrev-ref",
"HEAD",
},
);
const build_git_files = b.step("gitinfo", "builds git_build.o, git_commit.o, and git_tag.o");
build_git_files.dependOn(&branch.step);
// THEN LATER ...
const controller_exe = b.addExecutable(.{
.name = "controller",
.target = target,
.optimize = optimize,
});
controller_exe.step.dependOn(build_git_files);
But I can’t seem to capture the stdout.
I need to
- define the system command
- I think I have this
- Run it and capture stdout
- Run another system command (“
objcopy --input binary
”) - Capture that and add the object file
Ideally build_git_files
will contain 3 steps where I repeat the “run git command and then objcopy
it to a .o file”
Any help is welcome. Thanks in advance.
P.S.
I have seen the captureStdout()
functions, I just can’t get them to work.