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

Rust - w.a.s.m. support #9

Open
jordems opened this issue Feb 6, 2022 · 2 comments
Open

Rust - w.a.s.m. support #9

jordems opened this issue Feb 6, 2022 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@jordems
Copy link

jordems commented Feb 6, 2022

https://rustwasm.github.io/book/introduction.html

Not entirely sure of the schematics of how this would work with nx, or if this would even be considered in the scope of this project. But, I'm more so bringing it up as I'm curious.
As this may be a really cool thing to have as an nx library, as then it could export typescript from a barrel file to be used in a frontend application.

Any who, let me know what you think c:

@dannymcgee
Copy link
Contributor

This is definitely doable and probably a pretty common use case — I'll look into it when I get the chance.

@dannymcgee dannymcgee added the enhancement New feature or request label Feb 6, 2022
@dannymcgee dannymcgee self-assigned this Feb 6, 2022
@dannymcgee
Copy link
Contributor

Sorry for taking so long to update this issue! As of #15 you can build a wasm library by adding the target option to your project.json's build target and the crate-type to your Cargo manifest:

[package]
name = "my-wasm-library"
# ...

[lib]
crate-type = ["cdylib", "rlib"]
# ...
{
  "name": "my-wasm-library",
  "targets": {
    "build": {
      "executor": "@nxrs/cargo:build",
      "options": {
        "target": "wasm32-unknown-unknown",
        // ...
      }
    }
    // ...
  }
}

To be usable in a TypeScript project, you would also want to do some other stuff, like run wasm-bindgen after the build and update your tsconfig.json to add a path alias for the build output directory.

This is honestly not a huge priority for me, but nowadays Nx makes it pretty straightforward to do this kind of thing with custom local executors, so it would be fairly straightforward to write one that first runs the @nxrs/cargo:build executor and then runs wasm-bindgen on the build output. It would be cool to have this feature built in to the plugin someday, so I'll leave this open in the meantime. :)

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

No branches or pull requests

2 participants