Prebuild fbc+emscripten installer

Emscripten, WASM, and asm.js related questions
Post Reply
linuxanddos
Posts: 22
Joined: Oct 28, 2023 13:31

Prebuild fbc+emscripten installer

Post by linuxanddos »

Hello fb community,

I'm trying to build the fbc+emscripten compiler to build some programs and play around.
But the guide from https://freebasic.net/wiki/devbuildemscripten seems to be very extensive and complicated and seems to link to https://freebasic.net/wiki/DevBuildWindows which has even more tools and folders to manage.

Also, I'm not sure if this guild isn't outdated now.

So I want to ask if there are any prebuild version of the fbc+emscripten compiler - or if it would be possible for you to provide a script (or even a program written in FreeBasic) than automates all the downloading, unpacking, compiling etc. until you can run the command to compile your own programs.

I have a Linux and a Windows computer to try this.

Best Regards,

linuxanddos

EDIT: There are still some open questions (see below), but I have managed to create a Docker container building one of my FreeBasic programs for several OS' including emscripten.
Last edited by linuxanddos on Jul 25, 2024 11:00, edited 1 time in total.
angros47
Posts: 2338
Joined: Jun 21, 2005 19:04

Re: Prebuild fbc+emscripten installer

Post by angros47 »

Basically, you need FreeBasic for your system, and its source code. Then, you need to install Emscripten: under Linux, the procedure is something like:

Code: Select all

git clone https://github.com/emscripten-core/emsdk.git
cd emsdk
git pull
./emsdk install latest
./emsdk activate latest
source ./emsdk_env.sh
As described here: https://emscripten.org/docs/getting_sta ... loads.html

At this point, you need to compile the runtime libraries for Emscripten, you do it with:

Code: Select all

make rtlib gfxlib2 TARGET=asmjs-unknown-emscripten ENABLE_STANDALONE=1
You might have to manually copy the files :termlib_min.js , fb_shell.html , fb_rtlib.js , fbextra.x in the lib directory and in the lib/freebasic/js-asmjs directory

At this point, it should be able to work
linuxanddos
Posts: 22
Joined: Oct 28, 2023 13:31

Re: Prebuild fbc+emscripten installer

Post by linuxanddos »

Thanks. Now it is almost working (on Linux).

But if I try to compile, there is the following error:

Code: Select all

wasm-ld: error: unable to find library -lfb
wasm-ld: error: unable to find library -lfbgfx
wasm-ld: error: unable to find library -lfb
I think I've missed some environment variable, but sadly, I don't know which one.

EDIT: It seems like I do not have an /lib/freebasic directory.
linuxanddos
Posts: 22
Joined: Oct 28, 2023 13:31

Re: Prebuild fbc+emscripten installer

Post by linuxanddos »

I have found the folder: /usr/local/lib/freebasic/
Now it is compiling, but it seems like I have to enable async support...
linuxanddos
Posts: 22
Joined: Oct 28, 2023 13:31

Re: Prebuild fbc+emscripten installer

Post by linuxanddos »

Now my software is almost working.

But I need some conditional compiling distinguishing between emscripten and the other platforms.
Is there something like

Code: Select all

#ifdef __FB_DOS__ 
	'code here
#endif
for emscripten/wasm?
coderJeff
Site Admin
Posts: 4364
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Re: Prebuild fbc+emscripten installer

Post by coderJeff »

There is a builtin define, available since emscripten target was added to fbc:

Code: Select all

'' defined for '-target js-asmjs'
#ifdef __FB_JS__
#endif
Not in the wiki / manual, but should probably be added (even if exact naming changes in future).
fxm
Moderator
Posts: 12351
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Prebuild fbc+emscripten installer

Post by fxm »

New page added:
KeyPgDdfbjs → fxm [new page '__fb_js__']
and also all the induced links.
linuxanddos
Posts: 22
Joined: Oct 28, 2023 13:31

Re: Prebuild fbc+emscripten installer

Post by linuxanddos »

Somewhere in this forum I have read that it is possible to run JS code from your FreeBasic app. Sadly, I don't find this message again.

Instead, I found this: https://emscripten.org/docs/porting/con ... rom-native

How can I use this in FreeBasic?
dodicat
Posts: 8144
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Prebuild fbc+emscripten installer

Post by dodicat »

Windows, Normal fb (no emscripten) :

Code: Select all

Dim As Ubyte r
Dim Shared As String c
Do
    Read r
    If r=0 Then Exit Do
    c+=Chr(r)
Loop 

Function java(message As String) As String
    Dim As String s
    s+="WSH.Echo('"+message+"');"
    s+="var console = {"+Chr(10)
    s+="    info: function (s){"+Chr(10)
    s+="        WSH.Echo(s);"+Chr(10)
    s+="    }"+Chr(10)
    s+="}"+Chr(10)
    s+="var document = {"+Chr(10)
    s+="    write : function (s){"+Chr(10)
    s+="        WSH.Echo(s);"+Chr(10)
    s+="    }"+Chr(10)
    s+="}"+Chr(10)
    s+="var alert = function (s){"+Chr(10)
    s+="    WSH.Echo(s);"+Chr(10)
    s+="}"+Chr(10)
    s+="console.info("""+c+ """);"+Chr(10)
    s+="document.write(""\n\n\n Goodbye"");"+Chr(10)
    s+="alert("" Press any key to end . . ."");"+Chr(10)
    Return s
End Function


sub savefile(filename As String,p As String)
    Dim As Long n=Freefile
    If Open (filename For Binary Access Write As #n)=0 Then
        Put #n,,p
        Close
    Else
        Print "Unable to save " + filename:Sleep:End
    End If
End sub

Sub runscript(filename As String) 
    Shell "cscript.exe /Nologo "+ filename 
End Sub


savefile("script.js",java("Testing .js script file"))
runscript("script.js")
Kill "script.js"
Sleep


Data _
92,110,92,110,79,32,110,111,111,110,32,111,102,32,108,105,102,101,33,32,79,32,116,105,109,101,32,116,111,32,99,101,108,101,98,114,97,116,101,33,92,110,79,32,115,117,109,109,101,114,32,103,97,114,100,101,110,33,92,110,82,101,108,101,110,116,108,101,115,115,108,121,32,104,97,112,112,121,32,97,110,100,32,101,120,112,101,99,116,97,110,116,44,32,115,116,97,110,100,105,110,103,58,32,45,92,110,87,97,116,99,104,105,110,103,32,97,108,108,32,100,97,121,32,97,110,100,32,110,105,103,104,116,44,32,102,111,114,32,102,114,105,101,110,100,115,32,73,32,119,97,105,116,58,92,110,87,104,101,114,101,32,97,114,101,32,121,111,117,44,32,102,114,105,101,110,100,115,63,32,67,111,109,101,33,32,73,116,32,105,115,32,116,105,109,101,33,32,73,116,39,115,32,108,97,116,101,33,0
 
Lost Zergling
Posts: 600
Joined: Dec 02, 2011 22:51
Location: France

Re: Prebuild fbc+emscripten installer

Post by Lost Zergling »

I was delayed by a few Protoss Carriers, the hive and all the other Zerg got blown up, but I survived!
D.J.Peters
Posts: 8609
Joined: May 28, 2005 3:28
Contact:

Re: Prebuild fbc+emscripten installer

Post by D.J.Peters »

linuxanddos wrote: Apr 13, 2024 5:53 Somewhere in this forum I have read that it is possible to run JS code from your FreeBasic app. Sadly, I don't find this message again.
https://www.freebasic.net/forum/viewtopic.php?t=26545
linuxanddos
Posts: 22
Joined: Oct 28, 2023 13:31

Re: Prebuild fbc+emscripten installer

Post by linuxanddos »

Sorry, but I am searching for an option to call JavaScript code included in an .html file from an enscriptem FreeBasic build to use the capabilities of the browser. Like I stated here:
Instead, I found this: https://emscripten.org/docs/porting/con ... rom-native

How can I use this in FreeBasic?
I'm trying to use the functions of the link provided, but I do not know how to use it in a FreeBasic source code.
Post Reply