Skip to content

Conversation

coffeebe4code
Copy link

@coffeebe4code coffeebe4code commented Sep 18, 2025

Adding assets support. Let me know if I need to jump through any other hoops :)

@silbinarywolf
Copy link
Owner

Hm. It would be nice if an example like maybe minimal was updated to use this so that we're testing this behaviour in CI.
Out of curiosity, how have you personally used/tested this change?

@coffeebe4code
Copy link
Author

I built it locally, referenced my project, added the assets folder, and then loaded a png in raylib by path.

@coffeebe4code
Copy link
Author

I started trying to add it to minimal, and it didn't work. seems the regular filesystem commands don't work on zig.

aapt2link.addArg("-A"); // additional directory in which to find raw asset files
const val = dir.src_path.sub_path;

aapt2link.addArg(val);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update this to be:

aapt2link.addArg(val);
aapt2link.addFileInput(dir);

This will ensure if the file added is changed that the Zig compiler is aware of the change and we will re-run the aapt2link step.

From the Zig build system itself:

/// Adds an additional input files that, when modified, indicates that this Run
/// step should be re-executed.
/// If the Run step is determined to have side-effects, the Run step is always
/// executed when it appears in the build graph, regardless of whether this
/// file has been modified.
pub fn addFileInput(self: *Run, file_input: std.Build.LazyPath) void {
    file_input.addStepDependencies(&self.step);
    self.file_inputs.append(self.step.owner.allocator, file_input.dupe(self.step.owner)) catch @panic("OOM");
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like addFileInput is expecting only a file. There are compile issues with this method. I did not immediately see a directory implementation

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I mean the ideal thing would be adding each asset directly by walking the directory recursively.
It's something I've also had in the backlog for "addResourceDirectory".

Ideally just something that walks the tree and and at least does aapt2link.addFileInput(file) would be good.

@coffeebe4code
Copy link
Author

coffeebe4code commented Sep 19, 2025

image

here is the code.

        fn onStart(activity: *androidbind.ANativeActivity) callconv(.c) void {
            const file = std.fs.cwd().openFile("assets/hello_android.txt", .{}) catch @panic("file not found");
            defer file.close();
            const content = file.readToEndAlloc(std.heap.page_allocator, 200) catch @panic("OOM");
            log.debug("onStart => {s}", .{content});
            invoke(activity, "onStart", .{});
        }

@coffeebe4code
Copy link
Author

i forgot to mention that the logcat is logging a panic with "file not found"

@coffeebe4code
Copy link
Author

I've spent quite a few hours on this now. I even took a look at the raylib code for loading the image, since loading files works on raylib. I couldn't immediately see if anything special was done, so possibly the posix way of opening a file is different.

My best guess at this point is that zig std library on android the std.fs.cwd() method is not correct. I tried using walk through the cwd, and got a permissions error for reading the directory / on android. So certainly seems the case

This was meant to be an easy PR. I'm sorry its not working on the default android minimal project.

I can add the method you suggested to resources and assets which will help the build step link at some later point. aapt2link.addFileInput(file)

For right now we can leave this open.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants