Author Topic: Fresnel announcement  (Read 2785 times)

xinyiman

  • Hero Member
  • *****
  • Posts: 2264
    • Lazarus and Free Pascal italian community
Re: Fresnel announcement
« Reply #15 on: September 11, 2026, 11:06:07 am »
Fresnel WebAssembly: WASM runs correctly, but TMainForm is not created

Hi,

I'm trying to get the Fresnel WebAssembly backend working on Windows with a recent Lazarus/FPC trunk installation.

My environment is:

Windows
Lazarus trunk installed with fpcupdeluxe
FPC 3.3.1 trunk
Lazarus/FPC installation: C:\lazarus\20260903
Fresnel from the current Git repository
Skia4Delphi installed
Firefox for testing

I initially asked how to compile the Fresnel ComboBox demo for the browser and was advised to:

build pas2js if needed;
build the WASM cross-compiler;
reference the WASM binary from the browser host.

I successfully built ppcrosswasm32, located at:

C:\lazarus\20260903\fpc\bin\x86_64-win64\ppcrosswasm32.exe

I also found pas2js.exe at:

C:\lazarus\20260903\ccr\pas2js-rtl\bin\x86_64-win64\pas2js.exe
C:\lazarus\20260903\fpc\bin\x86_64-win64\pas2js.exe
Building the WASM

The original compile.cfg used:

-FUlib/wasm32-wasi

but on Windows this caused object files to be generated in an incorrect nested directory.

I changed it to:

-FUlib/wasm32-wasip1

and then I was able to successfully compile:

ComboBox.wasm

with:

"C:\lazarus\20260903\fpc\bin\x86_64-win64\ppcrosswasm32.exe" @compile.cfg ComboBox.lpr

The resulting WASM is approximately 6.4 MB.

WebHost

I then compiled the fresnelhost pas2js project. The generated files are:

browser.dom.js
browser.min.js
fresnelhost.js
hostconfig.js
ComboBox.wasm
index.html

I also built simpleserver from the Lazarus trunk and used it to serve the WebHost directory on:

http://localhost:4040

Serving the files over HTTP solved the CORS problem that occurred when opening index.html directly from file://.

The server initially returned JavaScript files as application/octet-stream, producing MIME warnings in Firefox, but the JavaScript was nevertheless executed.

First important problem: _initialize

The browser initially reported:

Loading and starting Webassembly module: ComboBox.wasm

Running Webassembly resulted in exception.

aExports[$Self.FRunEntryFunction] is not a function

I inspected the generated WASM exports and found:

memory
_start
_start_promising
wasiAlloc
wasiFree
__fresnel_tick
__fresnel_process_message
__fresnel_main_thread_wake
__fresnel_timer_tick
__fresnel_menu_click
...

There was no _initialize export.

The generated fresnelhost.js contained:

if ($Self.FRunEntryFunction === "") {
  if (aExports["_initialize"] != null) {
    aExports._initialize()
  }
  else aExports._start()
}
else aExports[$Self.FRunEntryFunction]();

However, FRunEntryFunction was set to _initialize, so the fallback to _start was not reached.

For diagnostic purposes, I modified this section so that if the requested entry point does not exist, it falls back to _start.

With that temporary change, the WASM starts successfully.

This is now working

After using _start, the browser console shows many Fresnel renderer messages, for example:

TWasmFresnelRenderer.DrawElBorder("TMainForm.Body1.TDiv.CheckBox")
TWasmFresnelRenderer.DrawElBorder("TMainForm.Body1.TDiv.GroupedBox")

and finally:

Wasm initialized, control now goes to Javascript event loop

So it appears that:

the WASM loads correctly;
the WASM executes;
Fresnel initializes;
the WASM renderer is active;
controls are being processed/rendered.
Current problem

The remaining error is:

Form resource TMainForm not found.
For resourceless forms CreateNew constructor must be used.

The browser then reports:

Wasm initialized, control now goes to Javascript event loop

but the actual form is not visible.

I checked the browser-specific entry point:

library wasmCombobox;

{$mode objfpc}{$H+}

uses
  nothreads,
  Fresnel,
  Fresnel.Forms,
  MainUnit;

begin
  Application.Initialize;
  Application.CreateFormNew(TMainForm, MainForm);
  Application.Run;
end.

So I am already using:

Application.CreateFormNew(TMainForm, MainForm);

and not Application.CreateForm.

I also checked MainUnit.pas. TMainForm derives from TFresnelForm and has an explicit CreateNew constructor:

constructor TMainForm.CreateNew(aOwner: TComponent);

which calls:

inherited CreateNew(aOwner);

and creates the controls programmatically.

I also temporarily added a log at the beginning of TMainForm.CreateNew, but that message never appeared.

Therefore, it seems that TMainForm.CreateNew is not actually being called, despite the application using:

Application.CreateFormNew(TMainForm, MainForm);

Instead, Fresnel appears to be trying to locate a form resource named TMainForm.

Another important detail

I also tried following the apparent official browser compilation command:

ppcrosswasm32 -tbrowser @compile.cfg wasmCombobox.lpr

but my FPC installation reports:

Error: Subtarget BROWSER specified but no corresponding config file fpc-browser.cfg found.

Therefore, at the moment I am using:

-Twasip1

to generate the working WASM, with the _start workaround described above.

My questions are therefore:

Is -tbrowser the correct target for the current Fresnel WebAssembly backend?
If so, where should fpc-browser.cfg come from when using an FPC/Lazarus trunk installation created with fpcupdeluxe?
Is the Form resource TMainForm not found error a consequence of compiling the application with -Twasip1 instead of the Fresnel browser target?
Why does Application.CreateFormNew(TMainForm, MainForm) appear not to call TMainForm.CreateNew?
What is the recommended/current build procedure for the Fresnel ComboBox WebAssembly demo on Windows?

At this point the WASM is definitely executing and Fresnel's WASM renderer is producing output; the remaining issue is getting the actual TMainForm instance displayed correctly.

Thanks for any guidance.
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

marcos-ebm

  • Jr. Member
  • **
  • Posts: 55
Re: Fresnel announcement
« Reply #16 on: September 18, 2026, 03:27:02 pm »
(Translator)

Will it also compile the app for Android? Or just for desktop?
Lazarus 3.0 / LAMW 0.8.6.4 - Gradle 8.5 - Jdk 21 - Ndk 21e - Windows 11

Thaddy

  • Hero Member
  • *****
  • Posts: 19978
  • Pointless static linking author
Re: Fresnel announcement
« Reply #17 on: September 18, 2026, 04:29:03 pm »
wasm is supported by Android, so yes, that would work, although I did not test that in this case.
Any "programmer" that knows only one programming language is not a programmer

xinyiman

  • Hero Member
  • *****
  • Posts: 2264
    • Lazarus and Free Pascal italian community
Re: Fresnel announcement
« Reply #18 on: September 21, 2026, 04:58:52 pm »
(Translator)

Will it also compile the app for Android? Or just for desktop?

If the question was addressed to me: I am trying to create a web app to be installed on a PC.
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

mattias

  • Administrator
  • Full Member
  • *
  • Posts: 226
    • http://www.lazarus.freepascal.org
Re: Fresnel announcement
« Reply #19 on: October 07, 2026, 03:35:10 pm »
I want to contribute, I see that the project relies on SKIA as a rendering engine, I will try allowing native OS OpenGL/GLES renderer that can optionally replace skia and keep the component dependent-less?, is this on the table? any particular coding convention?, also keeping Delphi support is possible.
Quote

There is already a native gtk3 renderer, a webassembly renderer, and a lcl renderer. They lack some features though.

The Fresnel Skia compiles with fpc 3.2.2+ and 3.3.1.

More renderers are welcome.

mattias

  • Administrator
  • Full Member
  • *
  • Posts: 226
    • http://www.lazarus.freepascal.org
Re: Fresnel announcement
« Reply #20 on: October 07, 2026, 03:37:41 pm »
I think that €50,- is excessive.

Detlef offers free access to individuals who cannot afford it.

Thaddy

  • Hero Member
  • *****
  • Posts: 19978
  • Pointless static linking author
Re: Fresnel announcement
« Reply #21 on: October 07, 2026, 03:43:15 pm »
That does not apply to me...But is good to know.
Any "programmer" that knows only one programming language is not a programmer

mattias

  • Administrator
  • Full Member
  • *
  • Posts: 226
    • http://www.lazarus.freepascal.org
Fresnel at International Pascal Café 24th Oct 2026
« Reply #22 on: October 07, 2026, 04:09:05 pm »
Learn how to create your first complete applications built with Fresnel on 24th October 2026.

Fresnel is an open source CSS based custom drawn visual component library, using Lazarus as IDE and form designer. Fresnel applications runs natively without LCL on all major platforms, including Android and in the browser. Fresnel can also be used inside an LCL application. See here what Fresnel is and what it is not: https://fresnel.freepascal.org/

The event:
https://www.blaisepascalmagazine.eu/inter-pascalcafe_october_24_2026/

Address: Netherlands, Kruispunt, Touwlaan 36, 3401 CB IJsselstein,

Blaisepascalmagazine offers free access to individuals who are interested but cannot afford it. Send your request to editor@blaisepascal.eu.

PierceNg

  • Sr. Member
  • ****
  • Posts: 450
    • SamadhiWeb
Re: Fresnel announcement
« Reply #23 on: November 03, 2026, 10:33:13 am »
Setup:

- Windows 11 Home host with WSL Ubuntu 22.04

- Freshly baked FPC trunk #82b9e12 dated 31 Oct 2026, on Ubuntu with aarch64, x86_64, armv7 and i686 Android targets

- GNU binutils 2.47 cross-built from source on Ubuntu

- Skia4Delphi's fork of Skia built for x86_64 (and aarch64 so they're the same) Android

- Android NDK r27d on Ubuntu

- Android Studio 'Rabbit' on Windows

=====

My Android experience report:

For demo/Android, I built x86_64 and aarch64 versions of libfresnelandroiddemo.so. The x86_64 target was built with text relocatable, as warned by the linker:

Code: Text  [Select][+][-]
  1. Free Pascal Compiler version 3.3.1 [2026/10/31] for x86_64
  2. Copyright (c) 1993-2026 by Florian Klaempfl and others
  3. Target OS: Android for x86-64
  4. Compiling /home/pierce/src/pascal/fresnel/demo/Android/lib/x86_64/Android/fresnelandroiddemo.lpr
  5. Compiling /home/pierce/src/pascal/fresnel/demo/Android/MainUnit.pas
  6. Compiling resource /home/pierce/src/pascal/fresnel/demo/Android/lib/x86_64/Android/fresnelandroiddemo.or
  7. Linking /home/pierce/src/pascal/fresnel/demo/Android/lib/x86_64/Android/libfresnelandroiddemo.so
  8. /home/pierce/pkg/cross/x86_64-linux-android/bin/x86_64-linux-android-ld.bfd: /home/pierce/pkg/fpc/lib/3.3.1/units/x86_64-android/rtl/system.o: warning: relocation in read-only section `.rodata.n_VMT_$SYSTEM_$$_TOBJECT'
  9. /home/pierce/pkg/cross/x86_64-linux-android/bin/x86_64-linux-android-ld.bfd: warning: creating DT_TEXTREL in a shared object
  10. 191 lines compiled, 4.0 sec

Compiling with '-Cg' did not help.

No such warning when building the aarch64 target.

The Android demo build.sh scripts calls a mkapk.sh script which isn't available. I put together an Android Studio project that builds debug APKs incorporating the libfresnelandroiddemo.so files as well as the Fresnel Java source code.

On my Windows host, on the Android device emulator, the APK crashed instantly. 'adb logcat' shows that the Android OS killed the app because libfresnelandroiddemo.so contains text relocatable code.

On my device (an old phone running LineageOS), the app also got killed, but for a different reason:

Code: Text  [Select][+][-]
  1. 21877   │ 11-03 16:30:51.266 11805 11805 D nativeloader: Load /data/app/~~EtMKHZmXu9XYMdZT4UKXGg==/org.freepascal.fresnel.demo-NIaFcNA
  2.         │ jDXrcOzhQnn0E1A==/base.apk!/lib/arm64-v8a/libfresnelandroiddemo.so using class loader ns clns-7 (caller=/data/app/~~EtMKHZmX
  3.         │ u9XYMdZT4UKXGg==/org.freepascal.fresnel.demo-NIaFcNAjDXrcOzhQnn0E1A==/base.apk!classes3.dex): dlopen failed: cannot locate s
  4.         │ ymbol "utext_openUChars" referenced by "/data/app/~~EtMKHZmXu9XYMdZT4UKXGg==/org.freepascal.fresnel.demo-NIaFcNAjDXrcOzhQnn0
  5.         │ E1A==/base.apk!/lib/arm64-v8a/libfresnelandroiddemo.so"...
  6. 21878   │ 11-03 16:30:51.267 11805 11805 D AndroidRuntime: Shutting down VM
  7. 21879   │ 11-03 16:30:51.269 11805 11805 E AndroidRuntime: FATAL EXCEPTION: main
  8. 21880   │ 11-03 16:30:51.269 11805 11805 E AndroidRuntime: Process: org.freepascal.fresnel.demo, PID: 11805
  9. 21881   │ 11-03 16:30:51.269 11805 11805 E AndroidRuntime: java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "utext_
  10.         │ openUChars" referenced by "/data/app/~~EtMKHZmXu9XYMdZT4UKXGg==/org.freepascal.fresnel.demo-NIaFcNAjDXrcOzhQnn0E1A==/base.ap
  11.         │ k!/lib/arm64-v8a/libfresnelandroiddemo.so"...

I see FPC's cwstring.pp loading libicuuc.so and libicui18n.so when 'ifdef android'. But these files aren't available on my device. I rebuilt the .so and APK after commenting out cwstring in fresnelandroiddemo.lpr's 'uses' section, but same outcome.

I believe libsk4d.a incorporates the ICU libraries? If indeed so then cwstring.pp may need rewriting for Android Fresnel.

=====

In summary:

- FPC trunk builds x86_64 .so with DT_TEXTREL, not acceptable by Android, AFAIUI.

- mkapk.sh is missing in the repo. Publishing it would save experimenters mucking around and getting it wrong, as I've probably done here.

- cwstring issue?

- Please publish your libsk4d build configs.

PierceNg

  • Sr. Member
  • ****
  • Posts: 450
    • SamadhiWeb
Re: Fresnel announcement
« Reply #24 on: November 04, 2026, 09:52:47 am »
- Please publish your libsk4d build configs.

Indeed it was my self-built libsk4d.a that came up short. Using the bundled version, It Works On My Phone!tm

 

TinyPortal © 2005-2018