Can't deploy Shopify Function written in Rust

Topic summary

Issue: Developers are encountering deployment failures when building Shopify Functions written in Rust. The error occurs during npm run deploy when executing cargo wasi build --release.

Error Details:

  • The build completes successfully but fails during wasm-opt optimization
  • wasm-validator throws an error: “unexpected false: all used features should be allowed”
  • The error output shows corrupted/garbled text in the stack trace

Affected Scenarios:

  • Product discount function (from “getting started” guide)
  • Cart transform extension
  • Occurs on both Windows and Mac environments

Workaround Found:
One user resolved the issue by reinstalling cargo-wasi:

cargo install cargo-wasi

This suggests the problem may stem from using an outdated version of cargo-wasi.

Status: The discussion remains open with limited responses. One developer has switched to JavaScript temporarily while awaiting a permanent solution.

Summarized with AI on November 17. AI used: claude-sonnet-4-5-20250929.

I’m trying to follow along with the “getting started” guide for the product discount, and whenever I run “npm run deploy”, I get the following error:

external error

Error coming from `cargo wasi build --release`

Command failed with exit code 1: cargo wasi build --release
   Compiling product-discount v1.0.0 (C:\Users\user\folder\functions-demo\extensions\product-discount)
    Finished release [optimized] target(s) in 1.90s
  Optimizing with wasm-opt
[wasm-validator error in function 0] unexpected false: all used features should be allowed, on
(i32.extend16_s
 (i32.sub
  (local.get $7)
  (local.tee $2
   (i32.sub
    (select
     (i32.add
      (local.tee $6
       (select
        (i32.add
         (local.tee $6
          (select
           (i32.add
            (local.tee $6
             (select
              (i32.add
               (local.tee $6
                (select
                 (i32.add
                  (local.get $7)
                  (i32.const -32)
                 )
                 (local.get $7)
                 (local.tee $2
                  (i64.lt_u
                   (local.tee $40
                    (i64.add
                     (local.get $39)
                     (local.get $36)
                    )
                   )
                   (i64.const 4294967296)
                  )
                 )
                )
               )
               (i32.const -16)
              )
              (local.get $6)
              (local.tee $2
               (i64.lt_u
                (local.tee $34
                 (select
                  (i64.shl
                   (local.get $40)
                   (i64.const 32)
                  )
                  (local.get $40)
                  (local.get $2)
                 )
                )
                (i64.const 281474976710656)
               )
              )
             )
            )
            (i32.const -8)
           )
           (local.get $6)
           (local.tee $2
            (i64.lt_u
             (local.tee $34
              (select
               (i64.shl
                (local.get $34)
                (i64.const 16)
               )
               (local.get $34)
               (local.get $2)
              )
             )
             (i64.const 72057594037927936)
            )
           )
          )
         )
         (i32.const -4)
        )
        (local.get $6)
        (local.tee $2
         (i64.lt_u
          (local.tee $34
           (select
            (i64.shl
             (local.get $34)
             (i64.const 8)
            )
            (local.get $34)
            (local.get $2)
           )
          )
          (i64.const 1152921504606846976)
         )
        )
       )
      )
      (i32.const -2)
     )
     (local.get $6)
     (local.tee $2
      (i64.lt_u
       (local.tee $34
        (select
         (i64.shl
          (local.get $34)
          (i64.const 4)
         )
         (local.get $34)
         (local.get $2)
        )
       )
       (i64.const 4611686018427387904)
      )
     )
    )
    (local.tee $5
     (i64.gt_s
      (local.tee $37
       (select
        (i64.shl
         (local.get $34)
         (i64.const 2)
        )
        (local.get $34)
        (local.get $2)
       )
      )
      (i64.const -1)
     )
    )
   )
  )
 )
)
[wasm-validator error in function 0] unexpected false: all used features should be allowed, on
(i32.extend16_s
 (i32.sub
  (i32.const -96)
  (local.get $2)
 )
)
[wasm-validator error in function 0] unexpected false: all used features should be allowed, on
(i64.extend16_s
 (i64.extend_i32_u
  (local.get $7)
 )
)
[wasm-validator error in function 0] unexpected false: all used features should be allowed, on
(i32.extend16_s
 (local.tee $6
  (i32.wrap_i64
   (i64.shr_u
    (i64.add
     (i64.mul
      (i64.sub
       (i64.extend16_s
        (i64.extend_i32_u
         (local.get $7)
        )
       )
       (i64.clz
        (i64.add
         (local.get $40)
         (i64.const -1)
        )
       )
      )
      (i64.const 1292913986)
     )
     (i64.const 82746495104)
    )
    (i64.const 32)
   )
  )
 )
)
[wasm-validator error in function 0] unexpected false: all used features should be allowed, on
(i32.extend16_s
 (local.get $7)
)
[wasm-validator error in function 0] unexpected false: all used features should be allowed, on
(i32.extend16_s
 (i32.sub
  (i32.const 0)
  (local.get $7)
 )
)
[wasm-validator error in function 0] unexpected false: all used features should be allowed, on
(i32.extend16_s
 (i32.sub
  (i32.const 0)
  (local.get $11)
 )
)
[wasm-validator error in function 1] unexpected false: all used features should be allowed, on
(i32.extend16_s
 (local.get $8)
)
[wasm-validator error in function 1] unexpected false: all used features should be allowed, on
(i32.extend16_s
 (select
  (i32.sub
   (i32.const 0)
   (local.get $3)
  )
  (i32.const -32768)
  (i32.lt_u
   (local.get $3)
   (i32.const 32768)
  )
 )
)
[wasm-validator error in function 1] unexpected false: all used features should be allowed, on
(i32.extend16_s
 (i32.sub
  (i32.const -96)
  (local.tee $7
   (i32.sub
    (select
     (i32.add
      (local.tee $2
       (select
        (i32.add
         (local.tee $2
          (select
           (i32.add
            (local.tee $2
             (select
              (i32.add
               (local.tee $2
                (select
                 (i32.add
                  (local.get $8)
                  (i32.const -32)
                 )
                 (local.get $8)
                 (local.tee $5
                  (i64.lt_u
                   (local.get $37)
                   (i64.const 4294967296)
                  )
                 )
                )
               )
               (i32.const -16)
              )
              (local.get $2)
              (local.tee $5
               (i64.lt_u
                (local.tee $35
                 (select
                  (i64.shl
                   (local.get $37)
                   (i64.const 32)
                  )
                  (local.get $37)
                  (local.get $5)
                 )
                )
                (i64.const 281474976710656)
               )
              )
             )
            )
            (i32.const -8)
           )
           (local.get $2)
           (local.tee $5
            (i64.lt_u
             (local.tee $35
              (select
               (i64.shl
                (local.get $35)
                (i64.const 16)
               )
               (local.get $35)
               (local.get $5)
              )
             )
             (i64.const 72057594037927936)
            )
           )
          )
         )
         (i32.const -4)
        )
        (local.get $2)
        (local.tee $5
         (i64.lt_u
          (local.tee $35
           (select
            (i64.shl
             (local.get $35)
             (i64.const 8)
            )
            (local.get $35)
            (local.get $5)
           )
          )
          (i64.const 1152921504606846976)
         )
        )
       )
      )
      (i32.const -2)
     )
     (local.get $2)
     (local.tee $5
      (i64.lt_u
       (local.tee $35
        (select
         (i64.shl
          (local.get $35)
          (i64.const 4)
         )
         (local.get $35)
         (local.get $5)
        )
       )
       (i64.const 4611686018427387904)
      )
     )
    )
    (local.tee $2
     (i64.gt_s
      (local.tee $35
       (select
        (i64.shl
         (local.get $35)
         (i64.const 2)
        )
        (local.get $35)
        (local.get $5)
       )
      )
      (i64.const -1)
     )
    )
   )
  )
 )
)
[wasm-validator error in function 1] unexpected false: all used features should be allowed, on
(i32.extend16_s
 (i32.add
  (i32.sub
   (local.get $14)
   (local.get $6)
  )
  (i32.const 1)
 )
)
[wasm-validator error in function 1] unexpected false: all used features should be allowed, on
(i32.extend16_s
 (local.tee $2
  (i32.sub
   (local.get $16)
   (local.get $13)
  )
 )
)
[wasm-validator error in function 1] unexpected false: all used features should be allowed, on
(i64.extend16_s
 (i64.extend_i32_u
  (local.get $8)
 )
)
[wasm-validator error in function 1] unexpected false: all used features should be allowed, on
(i32.extend16_s
 (local.tee $5
  (i32.wrap_i64
   (i64.shr_u
    (i64.add
     (i64.mul
      (i64.sub
       (i64.extend16_s
        (i64.extend_i32_u
         (local.get $8)
        )
       )
       (i64.clz
        (i64.add
         (local.get $37)
         (i64.const -1)
        )
       )
      )
      (i64.const 1292913986)
     )
     (i64.const 82746495104)
    )
    (i64.const 32)
   )
  )
 )
)
[wasm-validator error in function 1] unexpected false: all used features should be allowed, on
(i32.extend16_s
 (i32.sub
  (i32.const 0)
  (local.get $8)
 )
)
[wasm-validator error in function 1] unexpected false: all used features should be allowed, on
(i32.extend16_s
 (i32.sub
  (i32.const 0)
  (local.get $17)
 )
)
[wasm-validator error in function 1] unexpected false: all used features should be allowed, on
(i32.extend16_s
 (local.get $17)
)
[wasm-validator error in function 1] unexpected false: all used features should be allowed, on
(i32.extend16_s
 (i32.sub
  (local.get $17)
  (local.get $13)
 )
)
[wasm-validator error in function 1] unexpected false: all used features should be allowed, on
(i32.extend16_s
 (i32.add
  (local.get $17)
  (i32.const 1)
 )
)
[wasm-validator error in function 1] unexpected false: all used features should be allowed, on
(i32.extend16_s
 (local.get $17)
)
[wasm-validator error in function 27] unexpected false: all used features should be allowed, on
(i32.extend8_s
 (local.tee $7
  (i32.load8_u
   (i32.add
    (local.get $1)
    (local.get $3)
   )
  )
 )
)
[wasm-validator error in function 48] unexpected false: all used features should be allowed, on
(i32.extend16_s
 (i32.add
  (local.get $4)
  (i32.const 1)
 )
)
[wasm-validator error in function 48] unexpected false: all used features should be allowed, on
(i32.extend16_s
 (local.get $5)
)
[wasm-validator error in function 57] unexpected false: all used features should be allowed, on
(i32.extend16_s
 (local.get $3)
)
[wasm-validator error in function 60] unexpected false: all used features should be allowed, on
(i32.extend8_s
 (local.tee $1
  (i32.load8_u
   (local.get $5)
  )
 )
error: failed to process wasm at `C:\Users\user\folder\functions-demo\extensions\product-discount\target\wasm32-wasi\release\product-discount.rustc.wasm`

Caused by:
    `wasm-opt` failed to execute

Caused by:
    failed to execute "C:\\Users\\user\\AppData\\Local\\cargo-wasi\\0.1.27\\wasm-opt\\bin\\wasm-opt.exe" "C:\\Users\\user\\folder\\functions-demo\\extensions\\product-discount\\target\\wasm32-wasi\\release\\.tmptEWWAa\\input.wasm" "-Oz" "-o" "C:\\Users\\user\\folder\\functions-demo\\extensions\\product-discount\\target\\wasm32-wasi\\release\\product-discount.wasi.wasm" "--enable-bulk-memory" "--debuginfo"
        status: exit code: 1
1 Like

I am receiving this same issue when attempting to deploy the standard cart transform extension as well…on both Mac and Windows devices

Glad to know it isn’t just me. I tried on Windows 10 and 11. I am continuing my project with JavaScript for now.

I was running into this same issue, but it went away after re-running cargo install cargo-wasi.

I’m guessing I was using an outdated version.