akarpovskii / build.crab

Use Rust libraries in Zig
MIT License
11 stars 2 forks source link

Support multiple artifacts #7

Open levydsa opened 1 week ago

levydsa commented 1 week ago

Hey! Really cool project. I'm currently facing an issue with a library exporting more than one artifact on build. For now, I can just disable the other ones, but it would be nice to support this use case. Reading the code, it seems to just panic if filenames.len != 1. I might be wrong, but why not just copy the files in a loop? I can write a PR if that is more convenient.

akarpovskii commented 1 week ago

Hi, can you elaborate on your use case? I know on Windows you sometimes may get multiple files per target, or when creating shared libraries. Is it that, or something else?

The main issue here is how to pass all those files to Zig's build graph so that it knows about them. Otherwise you may get weird and unexpected behavior due to caching.

In other words, you may have to know beforehand what files your are going to get and either pass an argument for each of them, or somehow filter only the ones you need. And it becomes more complicated when you cross-compile because different targets may produce different number of outputs.

I definitely want to support this use case, but what would the interface be?

levydsa commented 1 week ago

The crate's crate-type was set to ["lib", "cdylib", "staticlib"], and was emiting each respective artifact. I think a extra field on CargoConfig to choose wich artifact you want should be fine. Or instead of pointing to a proper output artifact, only output the "dirname" with all the artifacts.

levydsa commented 1 week ago

Also, debug logging is enabled by default. Maybe add another option for that too. :)

akarpovskii commented 1 week ago

std.log.debug is only enabled when binaries are built in debug mode. You can pass .optimize = .ReleaseSafe to build.crab to build its binaries in release. Since it's not a library, you don't need to build it in debug :) See this for example.

I believe I had it in the readme, but it appears to be lost after an update.

akarpovskii commented 16 hours ago

So I finally had a chance to look into this. The reason I made it accept the out file argument is that there was no addOutputDirectoryArg, only addOutputFileArg. But looks like it was added in https://github.com/ziglang/zig/pull/19826 so I might be able to change the API to return a directory with all the artifacts at the price of raising the minimum Zig version to 0.13.0