Skip to content

StepOptions.preload_paths does not allow directories as input #24

Description

@miker2049

According to emscripten docs, --embed-file and --preload-file accept directory inputs, which will bundle everything in the directory into the js/.data file accordingly. Currently, an input with options like so will error:

        const opts: StepOptions = .{
            .optimize = optimize,
            .flags = emcc_flags,
            .settings = emcc_settings,
            .install_dir = install_dir,
            .out_file_name = "main.html",
            .preload_paths = &.{.{ .src_path = b.path("assets/") }},  // <--- here
        };

Relevant error:

...
run
└─ run dependency
   └─ install generated/
      └─ run dependency (main.html) failure
error: failed checking cache: /home/user/project/assets file_hash IsDir

Build Summary: 19/23 steps succeeded (1 failed)
run transitive failure
└─ run dependency transitive failure
   └─ install generated/ transitive failure
      ├─ run dependency (main.html) failure
      └─ run dependency (main.html) (+3 more reused dependencies)
...

Here is a hacky fix, the clear issue is .addFileArg deals with the cache and expects a file input. So, simply passing string of the path as the arg fixes the problem :

diff --git a/build.zig b/build.zig
index b16f992..3a06129 100644
--- a/build.zig
+++ b/build.zig
@@ -247,7 +247,7 @@ pub fn emccStep(
     if (options.preload_paths) |preload_paths| {
         for (preload_paths) |path| {
             emcc.addArg("--preload-file");
-            emcc.addFileArg(path.src_path);
+            emcc.addArg(path.src_path.getDisplayName());
         }
     }

There is probably better solution here.. getDisplayName for one is deprecated apparently.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions