#How to write a file into a lazypath folder
1 messages · Page 1 of 1 (latest)
I don't know what your target is, but b.addWriteFile creates a folder in a .zig-cache subdirectory. Is this your target? For what do you need this folder?
I purposedly tried to simplify the question. if you are curious, it is related to https://discord.com/channels/605571803288698900/1259479898981142529
But I don't expect that question to be answered, so I reduced the complexity to the very raw basics
I am literally stuck in the process of creating the file to begin with
Let alone its usage, I just cannot get it to be made
Should the file be in a .zig-cache subdirectory or not?
i don't mind. I just cannot get it made
- I have some bytes inside a const
- I want those bytes written to a file inside a LazyPath
- #stuck, doesn't write because I don't understand the syntax
build.zig:
const std = @import("std");
pub fn build(b: *std.Build) void {
const create_step = b.step("create", "Create a file");
const create_file = b.addWriteFile("foo", "bar");
create_step.dependOn(&create_file.step);
}
shell:
$ rm -r .zig-cache
$ find
.
./build.zig
./build.zig.zon
$ zig build create
$ find
.
./build.zig
./build.zig.zon
./.zig-cache
./.zig-cache/tmp
./.zig-cache/o
./.zig-cache/o/4b0d52780f92421c4b769ed9fc2e0f3c
./.zig-cache/o/4b0d52780f92421c4b769ed9fc2e0f3c/dependencies.zig
./.zig-cache/o/e82da1b58fb770e07829ebe8bcd8d74d
./.zig-cache/o/e82da1b58fb770e07829ebe8bcd8d74d/build.o
./.zig-cache/o/e82da1b58fb770e07829ebe8bcd8d74d/build
./.zig-cache/o/8714c3b07cdb6eeb21c7ca5acda584a3
./.zig-cache/o/8714c3b07cdb6eeb21c7ca5acda584a3/foo
./.zig-cache/h
./.zig-cache/h/20bae35774714c1ccaa12c26f8003e89.txt
./.zig-cache/h/timestamp
./.zig-cache/h/3c7ad56d47468b04ca42ee6c19994cc0.txt
./.zig-cache/z
./.zig-cache/z/7828b67ad03a02f11d2bd164c5ee1d12
$ cat ./.zig-cache/o/8714c3b07cdb6eeb21c7ca5acda584a3/foo
bar%
const patchWrite = B.addWriteFile(""++"zigcc.patch", internal.getPatch(B, "zigcc"));
const patchFile = patchWrite.addCopyFile(dir, "zigcc.patch");
B.getInstallStep().dependOn(&patchWrite.step);
```Mine is definitely wrong, but don't really understand why
the source should be a file not a directory
thats probably the problem
you should use addCopyDirectory if its a directory
its not a directory
I want that file into the directory
.nim is the target LazyPath directory
it should result in whateverjumbledmess/.nim/zigcc.patch
addWriteFile creates a new .zig-cache subdirectory. afaik the best solution is to use b.addWriteFiles() (note the plural of files) and copy everything from the original place to there
you cant add stuff to a cached directory
the path is the hash of its contents for a reason
if you do, it will inevitably break stuff
you could create an artifact that does the git clone, applies the diff, and writes the file
all in one exeutable
ok, can you propose an alternative to this simple bash script?
git clone URL folder
cp file.patch folder/file.patch
cd folder
git apply file.patch
./build.sh
```Because that's all I want to do
at this point I'm even considering writing the thing in bash, tbh
you could keep it a bash script sure, although ofc you could just write it with zig
but if you dont mind relying on a shell and coreutils its whatever
basically
for one-time tasks that you are expected to run once after checking out the repo, you're probably better of using a shell script
well that's what I don't want to do. but Its been hours and 5sloc of bash are still stuck in the very first line only working
so it was a statement of frustation, not really of intent. I don't want to do it in bash
youd want to use addSystemCommand(&.{“/bin/sh”, “script.sh”}
but then script.sh should take an output directory at least so that the build system can cache it well
but then its not cross-platform, and back to square1
because if I'm even using build.zig is to make it cross-platform to begin with
you could just write it in zig, copying files is easy, calling system commands is easy
instead of using a shell script
and then its cross platform
still relies on a git system command being available but its whatever
git+zig is all I'm willing to depend on, yeah
honestly not a bad idea
I really don't understand how people don't understand the frustration on the buildsystem tools, when 5sloc of bash becomes this hell
imagine a new user facing that... like... 
But that's a topic for another day I guess
I assume youre fine rewriting the shell script in zig so ill just show you what youd do after that:
const git_run_step = b.addRunArtifact(git_rool_thing);
git_run_step.addOutputDirectoryPath(“foo”);
thats all
what?
its just a completely different thing
you're generally not expected to patch the source code you're building from using the zig build system