Re: [Lazarus] FPC and WebAssembly

2021-12-25 Thread Salvatore Coppola via lazarus
Merry Christmas prof. and all of you

⁣Ottieni BlueMail per Android ​

Il giorno 24 Dic 2021, 14:13, alle ore 14:13, Michael Van Canneyt via lazarus 
 ha scritto:
>
>Hello,
>
>I'm glad to anncounce that FPC now covers working with webassembly in
>the
>browser.
>
>Because pictures say more than a thousand words, 3 demos:
>
>A modest "hello, world" variation:
>
>https://www.freepascal.org/~michael/pas2js-demos/wasienv/simple/
>
>A (limited) terminal emulation:
>
>https://www.freepascal.org/~michael/pas2js-demos/wasienv/terminal/
>
>And yes, we can do graphics too:
>
>https://www.freepascal.org/~michael/pas2js-demos/wasienv/terminal/
>
>In all 3 cases:
>- The webassembly program was created with the FPC webassembly target.
>
>- The hosting environment is created using pas2js.
>
>This is just initial hosting support, there is lots of work to be done.
>
>The webassembly compiler works very well, and is integrated in the
>compiler testsuite.
>
>More info can be found in:
>https://wiki.freepascal.org/WebAssembly/Compiler
>https://wiki.freepascal.org/WebAssembly/Roadmap
>
>Our little contribution to a Merry Christmas for everyone...
>
>Michael.
>--
>___
>lazarus mailing list
>lazarus@lists.lazarus-ide.org
>https://lists.lazarus-ide.org/listinfo/lazarus
-- 
___
lazarus mailing list
lazarus@lists.lazarus-ide.org
https://lists.lazarus-ide.org/listinfo/lazarus


Re: [Lazarus] FPC and WebAssembly

2021-12-25 Thread Kostas Michalopoulos via lazarus

Hello,


I'm glad to anncounce that FPC now covers working with webassembly in the
browser.


Sounds great. I did a quick compile for the wasi target and seemed to 
work fine with a simple helloworld-style test. So i decided to try and 
port a game i made last year[0] - initially made for an MS-DOS game jam, 
but added a bunch of ports later and wanted to make a web-based one too.


I decided to go with a similar approach to the one i used for Android, 
with the game compiled into a library (or a wasm file for here) and a 
"stub" that loads the library and passes events, etc to it.


However no matter what i try, it always seems to fail when (i guess) 
tries to link or assemble the first unit (the unit doesn't do anything, 
just defines an entity class).


By default it gets this error which happens after it compiles everything 
(SndEmit.o is the object file for the unit, it is just the first unit it 
tries to link/compile):


wasm-ld: error: ./Engine/SndEmit.o: invalid relocation function index
Error: Error while linking

If i pass -Awabt to use the wasa assembler (thinking that there might be 
something wrong with the object files), it then has the error:


SndEmit.pas(171) Fatal: Internal error 2019093001

(The unit is 171 lines long)

Also there are a bunch of "steam read error" errors, often after 
"assembling someunitname" (though not all "assembling someunitname" have 
such an error after them).


If i pass -Allvm-mc to use LLVM's assembler, i get a bunch of errors 
from a different unit (Misc):


Compiling ./Engine/Misc.pas
Assembling misc
./Engine/Misc.wat:5082:3: error: symbol 
MISC$_$TSTRINGKEYVALUESET_$__$$_INDEXOFKEY$ANSISTRING$$LONGINT missing 
.functype
call 
MISC$_$TSTRINGKEYVALUESET_$__$$_INDEXOFKEY$ANSISTRING$$LONGINT

^
./Engine/Misc.wat:5412:3: error: symbol 
MISC$_$TSTRINGKEYVALUESET_$__$$_INDEXOFKEY$ANSISTRING$$LONGINT missing 
.functype
call 
MISC$_$TSTRINGKEYVALUESET_$__$$_INDEXOFKEY$ANSISTRING$$LONGINT

^
./Engine/Misc.wat:5606:3: error: symbol 
MISC$_$TSTRINGKEYVALUESET_$__$$_INDEXOFKEY$ANSISTRING$$LONGINT missing 
.functype
call 
MISC$_$TSTRINGKEYVALUESET_$__$$_INDEXOFKEY$ANSISTRING$$LONGINT

^
./Engine/Misc.wat:6023:3: error: 3 superfluous return values
end_function
^
./Engine/Misc.wat:6272:3: error: 1 superfluous return values
end_function
^
./Engine/Misc.wat:6496:3: error: 1 superfluous return values
end_function
^
./Engine/Misc.wat:6681:3: error: 1 superfluous return values
end_function
^
Misc.pas(150) Error: Error while assembling exitcode 1

Note that i have LLVM 13 installed but also tried removing it and 
installing LLVM 11 and didn't make any difference. Also FWIW i'm calling 
the ppcrosswasm32 executable directly and have it installed in 
~/Apps/fpc, though it shouldn't make a difference (and the simple hello 
world code compiled anyway so the compiler setup should be fine).


Is there anything i am missing/not setting up correctly (e.g. i didn't 
tried with the "embedded" target - i tried to build FPC with it first 
but got some errors so i didn't explore further and went with "wasi" 
instead that seemed to work)? AFAIK i do not use any of the 
functionality that isn't implemented in the Roadmap page in the wiki.


Kostas

[0] https://bad-sector.itch.io/post-apocalyptic-petra
--
___
lazarus mailing list
lazarus@lists.lazarus-ide.org
https://lists.lazarus-ide.org/listinfo/lazarus