DioxusLabs / DioxusLabs/dioxus

using asset! to import build.rs outputs in a crate in a workspace

Open
#4,426 3 comments 3 reactions 0 assignees View on GitHub
bug
Dominant language
Rust
Stars
39.1k
Forks
1.9k
Avg merge
4d 10h
Merged PRs (30d)
4

Description

**Problem**

app I'm writing that lives in a multi-crate workspace, I've got a build script that generates an asset. Generally, with build scripts you're encouraged to write the results out to a location pointed to by the env var "OUT_DIR".

OUT_DIR is set by cargo and is a subdirectory in $WORKSPACE_ROOT/target

It seems that asset! doesn't allow users to point at things in $OUT_DIR.

**Steps To Reproduce**

Create a new workspace based project, and write a build.rs that writes some asset to $OUT_DIR/junk.css.
import it as an asset:
`const JUNK_CSS: Asset = asset!(concat!(env!("OUT_DIR"), "/junk.css"));`

1) asset requires a static str as a parameter.
2) even if I manually expand it to a static str(in my case "../target\debug\build\ui-82050a64fa3cc57c\out\junk.css"), since OUT_DIR is outside the crate(but still in the workspace) it'll fail:
`const JUNK_CSS: Asset = asset!("../target\debug\build\ui-82050a64fa3cc57c\out\junk.css");`
with
```
Asset path C:\dioxus_app_ui\target\debug\build\ui-82050a64fa3cc57c\out\junk.css is invalid. Make sure the asset exists within this crate.
```

here's my build.rs that lives in a "ui" crate:
```
use std::env;
use std::fs;
use std::path::PathBuf;

fn main() -> Result<(), Box> {
let out_dir = env::var("OUT_DIR").unwrap();

let junk_css_path = PathBuf::from(out_dir).join("junk.css");

println!("cargo:info=junk.css path= {junk_css_path:?}");

let css_contents = "body { background: pink; }";

fs::write(&junk_css_path, css_contents)?;

println!("cargo:rerun-if-changed=build.rs");

Ok(())
}
```
-
-
-

**Expected behavior**

I'd hope for a way where I could use $OUT_DIR, and also point at a file outside the current crate

**Screenshots**

**Environment:**

- Dioxus version: 0.6.3
- Rust version: 1.88.0
- OS info: Windows 11
- App platform: web,desktop, and mobile but I'm using asset here in a shared "ui" crate

**Questionnaire**

I'm interested in fixing this myself but don't know where to start. Perhaps another macro in the "asset" family?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.