Skip to content

Musings on an architecture that doesn't need a custom linker #12

@madsmtm

Description

@madsmtm

I just read https://github.com/wasm-bindgen/js-bindgen/blob/main/doc/FAQ.md, very nice overview!

As I understand it, to create web-sys, you'd basically do:

  • Pre-generate #[js_sys::js_sys(...)] macro invocations.
  • Inside js_sys::js_sys, generate an assembly string placed in a custom js_bindgen.assembly link section that contains a "thunk" function that calls the symbol that you want to call with the ABI that Rust expects.
  • Link to and call that thunk with #[link_name = "..."].
  • When linking with the custom linker, grab the data from those custom js_bindgen.* sections, extract and assemble them, and turn them into an object file that the actual linker can work with.

I get that the string can't be constructed at macro time if you want to use Rust types to specify how it behaves, but that doesn't sound like it'd be needed for e.g. web-sys, if you're generating from IDL you're gonna have enough information available to also create the required assembly for the thunk?

That is, it isn't clear to me why you don't instead do the following?

  • Pre-generate thunk invocations using #[link_name = "..."].
  • Pre-generate a bunch of separate *.wat files that contains all the thunks.
  • Assemble the thunks in build.rs.

This has the downside that it would duplicate the data (though could be remediated by placing e.g. gen_AbortController.rs right next to gen_AbortController.wat), and that there is no longer a "single source of truth", but with the benefit that you don't need a custom linker?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions