Recent

Author Topic: The WASM32-compiler modes doesn't export routines.  (Read 550 times)

jddev

  • Newbie
  • Posts: 6
The WASM32-compiler modes doesn't export routines.
« on: April 14, 2025, 01:03:38 am »
Hi, all.
WASM support is quite attractive to me, but documentation is rare at this point.
For testing purposes I want to embed following code on my website:
Code: Pascal  [Select][+][-]
  1. library sitehelpers;
  2.  
  3. uses sysutils;
  4.  
  5. function visitedAt(): AnsiString;
  6. begin
  7.         visitedAt := DateTimeToStr(Now, false) + ' (Systemtime)';
  8. end;
  9.  
  10. exports
  11.         visitedAt;
  12.        
  13. End.
  14.  

Some explanations:
a) Due to the fact the "embedded" target only compiles libraries and units I choose "library", this generates a binary withaout wasm-extention.
b) neither the direct saved wat (-a switch) nor the reversed one (wasm2wat) contain an export statement for vsitedAt(), but a complicated mangled name for it. Both files are provided in the attached archive.
c) compiling it as a program in WASI-mode builds an executble (with .wasm extention) , which runs in wasmtime but doesn't work in my browsers.

Thanks in advance and greets,
Jonathan

PierceNg

  • Sr. Member
  • ****
  • Posts: 401
    • SamadhiWeb
Re: The WASM32-compiler modes doesn't export routines.
« Reply #1 on: April 14, 2025, 05:25:15 am »
c) compiling it as a program in WASI-mode builds an executble (with .wasm extention) , which runs in wasmtime but doesn't work in my browsers.

You need to set up the .wasm for the browser environment with Javascript. See pas2js Wasm examples implementing driver programs in Pascal that get transpiled to Javascript, that load other compiled-to-Wasm Pascal programs. Also my game of life demo.

jddev

  • Newbie
  • Posts: 6
Re: The WASM32-compiler modes doesn't export routines.
« Reply #2 on: April 14, 2025, 01:39:04 pm »
Hi.
Okay, this explains why it doesn't work through the WASM-JS interface, described at https://developer.mozilla.org/de/docs/WebAssembly/Reference/JavaScript_interface.
I'm strugglling with the configuration of pas2js for now. It doesn't seem to parse paths in the same way the standard compiler does and doesn't accept globs/wildcards like '*' in such paths.

Greets,
Jonathan

PierceNg

  • Sr. Member
  • ****
  • Posts: 401
    • SamadhiWeb
Re: The WASM32-compiler modes doesn't export routines.
« Reply #3 on: April 14, 2025, 04:47:29 pm »
Hi.
Okay, this explains why it doesn't work through the WASM-JS interface, described at https://developer.mozilla.org/de/docs/WebAssembly/Reference/JavaScript_interface.
I'm strugglling with the configuration of pas2js for now. It doesn't seem to parse paths in the same way the standard compiler does and doesn't accept globs/wildcards like '*' in such paths.

Plain Javascript works too. See https://github.com/PierceNg/wasm-demo/blob/pn/lyff/htdocs/main.js

jddev

  • Newbie
  • Posts: 6
Re: The WASM32-compiler modes doesn't export routines.
« Reply #4 on: April 14, 2025, 08:23:56 pm »
Hi.
I found the root of the problem.
The generated wasm d oesn't report the MIME-Type to the Browser and so the promise in the loading code can't be fullfilled. If I get this fixed, the wasm should load correctly with the WASM-JS API posted above.

Greets,
Jonathan

 

TinyPortal © 2005-2018