Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Having trouble in workspace with multiple targets #311

Open
mainrs opened this issue Nov 21, 2022 · 2 comments
Open

Having trouble in workspace with multiple targets #311

mainrs opened this issue Nov 21, 2022 · 2 comments

Comments

@mainrs
Copy link

mainrs commented Nov 21, 2022

I have an application that is setup as a cargo workspace. Some crates are plugins that should be compiled to WASM. How do I setup my flake to compile certain crates to wasm32-wasi target? The cross-compilation example only shows how to do it for a single root crate.

@psionic-k
Copy link
Member

Lean on lazy evaluation and on-demand building. Nix won't try to evaluate everything your expressions hypothetically define, only what you put in outputs. When you ask it to build an output, only the expressions that are actually evaluated can result in building.

Create a wasm32-wasi workspace and a native workspace. Pick only what you need when defining package outputs.

So basically your code will look the body of a cross example + the body of a host-host (native) example, and you will pick some outputs of those two things for your flake outputs. For defining a workspace shell, you can again do both by using devShells, but only one will be active at a time. Keep in mind, adding the two shells together at the same time is not fundamentally easy if there are collisions of variables and binaries that should be on PATH

You can even define the wasm32-wasi space first and use it as an input to the native workspace, pulling finished wasm32-wasi outputs into buildInputs

There is cleanup planned to make this workflow use more compact expressions. There's definitely a plan to add a wasm + Rust server + container example, which will motivate the development of more compact expressions using an override-like API

@psionic-k
Copy link
Member

Upcoming solution will make these overrideable. The present style of duplicating expressions will go away.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants