ziglang / zig

General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.
https://ziglang.org
MIT License
32.79k stars 2.39k forks source link

absolute paths in @embedFile always reports embed of file outside package path #14088

Open peterino2 opened 1 year ago

peterino2 commented 1 year ago

Zig Version

0.11.0-dev.955+1b86a628a

Steps to Reproduce and Observed Behavior

Hi, I'm upgrading my project neonwood to master

i just want to check if anyone else is running into this but it seems absolute paths on windows are always considered "outside of package" for purposes of @embedFile even if the path is inferior

eg. for a file which exists at D:\uproj\NeonWood\engine\zig-cache\resources.zig this yields an issue

pub const triangle_vert_static align(8) = @embedFile("D:\\uproj\\NeonWood\\engine\\zig-cache\\modules\\graphics\\shaders\\triangle_static.vert.spv").*;

zig-cache\resources.zig:5:54: error: embed of file outside package path: 'D:\uproj\NeonWood\engine\zig-cache\modules\graphics\shaders\triangle_static.vert.spv'

This is OK

pub const triangle_vert_static align(8) = @embedFile("modules/graphics/shaders/triangle_static.vert.spv").*;

Expected Behavior

I would expect absolute paths would work for purposes of embedfile if the path is within the package root.

Either that or the documentation for embed file should clearly state that it only accepts relative paths.

current documentation states:

path is absolute or relative to the current file, just like @import.

andrewrk commented 1 year ago

I think this issue will address the use case: #14553

Also the langref for @embedFile should be updated along with resolving this issue - currently it says that absolute paths are allowed.

peterino2 commented 2 months ago

Damn I need to check my github messages more often I didn't even realize you responded.

I tried out the new embedfile behaviour with addAnonymousImports and it works exactly as advertised on the tin. Love it!

I'm happy closing this issue. (not sure if i should do that or let someone from zig do that)