Rust size limits and tips

Hi, I’ve been having a rough time trying to find a solution to this so I’ll seek for some help.

In a gist, I’m aware that there are limits for size and instructions as far as any language goes but I’m trying to re-do my Typescript function in Rust to see if this can be achieved. My business logic envisages JWT validation and therefore crypto functions, which I’d like to make use through jwt_simple - Rust

Issue stems from the fact that as soon as I fetch my PEM and try to ES256PublicKey::from_pem it and then verify a token with public_key.verify_token::<NoCustomClaims> the wasm blows up and I get over the 256 KB limit.

At this point I’m trying to implement the tips from the docs but having a hard time at it: Rust for Functions

In particular, how would I go and use wasm-snip part in the deploy? Should I include that command in the extension.toml somehow? I have ran the command via terminal and the decrease in size is noticeable but how would I go then to just release that .wasm instead of the one that gets recompiled when I shopify app deploy ?

Thanks

Hi Nello,

If you have custom commands you wish to run as part of your function build, you can create something like a bash script or Makefile, and then configure the command and path in the [extensions.build] section of your extension.toml.

More information on this configuration here:

-Nick

Yeah, I ended up figuring out that I had to make something along those lines and put the command in a bash script to sort the deploy out.

Unfortunately, I didn’t manage to squeeze both a Public Key parse and a JWT validation into the .wasm; the Rust crate I found (jwt_simple) brought along about 140KB worth of stuff and even with wasm-snip and wasm-opt I didn’t manage to find a way to make them fit (along with the serde_json::parse stuff from attributes and a few more bits).

I reworked the business logic to use a different route to tackle what I was trying to solve.

I’ve only been dealing with Rust for the last few days so I consider that a success in any case. :smiley:

Thanks!