DioxusLabs / dioxus

Fullstack app framework for web, desktop, mobile, and more.
https://dioxuslabs.com
Apache License 2.0
21.44k stars 826 forks source link

Per platform dist directory #2692

Closed luveti closed 2 weeks ago

luveti commented 3 months ago

Feature Request

Having a per platform dist directory allows one to run dx serve multiple times without the build failing.

We're currently patching Dioxus.toml right before running dx serve to get around this:

# serve desktop
sed -i.bak 's|out_dir = ".*"|out_dir = "dist/desktop"|g' Dioxus.toml
rm Dioxus.toml.bak
dx serve --platform desktop

# serve fullstack
sed -i.bak 's|out_dir = ".*"|out_dir = "dist/fullstack"|g' Dioxus.toml
rm Dioxus.toml.bak
dx serve --platform fullstack

But this no longer works since this commit https://github.com/DioxusLabs/dioxus/commit/8b5ad5d925555c38fe2e6d823c51587e54424cb9. The cli now places files in the target/dx-dist directory. Our new workaround was going to be:

# serve desktop
export CARGO_TARGET_DIR="target/desktop"
dx serve --platform desktop

# serve fullstack
export CARGO_TARGET_DIR="target/fullstack"
dx serve --platform fullstack

But the new code does not follow CARGO_TARGET_DIR, and instead uses the hard-coded value target.

Implement Suggestion

Here's my change that makes use of CARGO_TARGET_DIR:

let mut dist_dir = crate_config.workspace_dir()
    .join(std::env::var("CARGO_TARGET_DIR").as_ref().map(|x| x.as_str()).unwrap_or("target"))
    .join("dx-dist");

Septimus has suggested including the platform at the end of the dist_dir could be a nice way to support this:

crate_config.dioxus_config.application.out_dir = dist_dir
            .join(crate_config.executable_name())
            .join(self.platform().feature_name());
ochrons commented 2 months ago

The hardcoded workspaceroot/target/dx-dist will also cause issues when there are more than one Dioxus project in the workspace.

jkelleyrtp commented 2 weeks ago

Closed by #2779