Dioxus assets in workspace root?

I'm having trouble finding the right documentation for this.

I have the following structure for a workspace

  • crates
    • my_library <-- has tests that depend on fonts
    • my_library_dioxus <-- a dioxus web demo for my library
  • fonts <-- some otfs with their own individual licenses
  • Cargo.toml

I'm trying to declare asset!s within my_library_dioxus to include the fonts from the workspace, but assert! (which is anchored on the crate root) doesn't seem to allow references to ../../fonts/*. Is there a way to have it reference the contents of fonts? Or does it require duplicating the fonts/ directory within the my_library_dioxus crate?

What is the actual error message? But yes, looks to me like assets can only be in a subdirectory of the manifest dir (where your package's Cargo.toml file is) or the output directory (defaults to a target/ directory in your workspace). A soft link to your assets in my_library_dioxus should probably suffice.

I had tried a relative symlink before and it didn't work. Thanks for the suggestion though.

Errors are different for hot-reloading and dx build. These are the errors for dx build --package my_library_dioxus. Say, the font is at $workspace_root/fonts/FontFile-Regular.otf, I get the following messages (copy-pasted with paths replaced).

  1. Relative path:

    const FONT: Asset = asset!("../../fonts/FontFile-Regular.otf");
    

    I get

      1.25s  INFO  error: Asset at ../../fonts/FontFile-Regular.otf doesn't exist
      --> crates/my_library_dioxus/src/main.rs:15:21
       |
    15 | const FONT: Asset = asset!("../../fonts/FontFile-Regular.otf");
       |                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    
  2. Relative path with /:

    const FONT: Asset = asset!("/../../fonts/FontFile-Regular.otf");
    

    I get

    1.18s  INFO  error: Asset path /path/to/workspace/fonts/FontFile-Regular.otf is invalid. Make sure the asset exists within this crate.
    --> crates/my_library_dioxus/src/main.rs:15:21
     |
    15 | const FONT: Asset = asset!("/../../fonts/FontFile-Regular.otf");
     |                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    
    
  3. Symlink: Creating an assets/fonts subdirectory and adding a relative-path symlink:

    const FONT: Asset = asset!("/assets/fonts/FontFile-Regular.otf");
    

    I get

      1.23s  INFO  error: Asset path /path/to/workspace/fonts/FontFile-Regular.otf is invalid. Make sure the asset exists within this crate.
      --> crates/my_library_dioxus/src/main.rs:15:21
       |
    15 | const FONT: Asset = asset!("/assets/fonts/FontFile-Regular.otf");
       |                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    
  4. Real file: With the same FONT definition as (3), replacing the symlink with a copy of the font file makes it succeed.