What happened to the Emscripten branch?

Emscripten, WASM, and asm.js related questions
Post Reply
angros47
Posts: 2323
Joined: Jun 21, 2005 19:04

What happened to the Emscripten branch?

Post by angros47 »

I see that there has been no development in the last years. I wonder if that branch could be merged with the original one, or if it is too different.
coderJeff
Site Admin
Posts: 4326
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Re: What happened to the Emscripten branch?

Post by coderJeff »

The original is still there at https://github.com/freebasic/fbc/tree/emscripten and every once and a while, I merge the master branch in to emscripten and push it to my own fork on https://github.com/jayrm/fbc/tree/emscripten

It looks really cool, and I want to try it, but I haven't had a chance to get it working.

EDIT:
to get it merged in to master, that is the official distribution, someone has to be willing to commit the time to support it. As in if freebasic is going to advertise that it supports emscripten build, then it needs documentation, packaging, etc, so that anyone can use it.
angros47
Posts: 2323
Joined: Jun 21, 2005 19:04

Re: What happened to the Emscripten branch?

Post by angros47 »

coderJeff wrote:The original is still there at https://github.com/freebasic/fbc/tree/emscripten and every once and a while, I merge the master branch in to emscripten and push it to my own fork on https://github.com/jayrm/fbc/tree/emscripten
A patch for fbc.bas:

Code: Select all

--- fbc.bas	2020-08-31 20:48:38.000000000 +0200
+++ src/compiler/fbc.bas	2020-10-31 01:26:07.016517629 +0100
@@ -133,7 +133,7 @@
 static shared as zstring * 16 toolnames(0 to FBCTOOL__COUNT-1) = _
 { _
 	"as", "ar", "ld", "gcc", "llc", "dlltool", "GoRC", "windres", "cxbe", "dxe3gen", _
-	"llvm-as", _
+	"emcc", _
 	"emar", _
 	"emcc", _
 	"emcc"  _
@@ -2634,7 +2634,7 @@
 	if( fbGetOption( FB_COMPOPT_TARGET ) <> FB_COMPTARGET_JS ) then
 		ext = @".asm"
 	else
-		ext = @".llvm"
+		ext = @".s"
 	end if
 
 	if( stage = 1 ) then
@@ -3152,6 +3152,11 @@
 			end if
 		endif
 	end if
+
+	if( fbGetOption( FB_COMPOPT_TARGET ) = FB_COMPTARGET_JS ) then
+		ln += "-c "
+	end if
+
 	ln += """" + hGetAsmName( module, 2 ) + """ "
 	ln += "-o """ + *module->objfile + """"
 	ln += fbc.extopt.gas
VANYA
Posts: 1834
Joined: Oct 24, 2010 15:16
Location: Ярославль
Contact:

Re: What happened to the Emscripten branch?

Post by VANYA »

I've tried Emscripten on Linux 64-bit, but:

when compiling source code v1ctor , i am getting errors:
Exception in thread Thread-3:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
self.run()
File "/usr/lib/python2.7/threading.py", line 754, in run
self.__target(*self.__args, **self.__kwargs)
File "/usr/lib/python2.7/multiprocessing/pool.py", line 392, in _handle_results
task = get()
TypeError: __init__() takes at least 3 arguments (1 given)
and compilation stops (hangs)

Unfortunately, I can't use it. It may be necessary to use older versions of Linux with older libraries Emscripten, python, etc.
coderJeff
Site Admin
Posts: 4326
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Re: What happened to the Emscripten branch?

Post by coderJeff »

@angros47,
Would you prefer a new rebase of emscripten on to current fbc 1.08 fbc/master? I don't mind doing that. For really old branches I find it easier to periodically rebase the changes up the development tree rather than try to merge something really old in to latest development.

If you and others are interested, I can merge the changes in to fbc 1.08. I don't know much about the emscripten target so I would be counting others to provide information and patches if it gets added to current fbc 1.08.
angros47
Posts: 2323
Joined: Jun 21, 2005 19:04

Re: What happened to the Emscripten branch?

Post by angros47 »

That would surely help (the version in your github branch isn't already the 1.08 version?). And I agree, it should be merged in the official version (as soon as it works enough at least for an "hello world")
angros47
Posts: 2323
Joined: Jun 21, 2005 19:04

Re: What happened to the Emscripten branch?

Post by angros47 »

VANYA wrote:I've tried Emscripten on Linux 64-bit, but:
Which version did you use? V1ctor's one, or CoderJeff's one? Also, what happens with a simple hello world example? Can you compile it? Can you run it?

I am using CoderJeff's version. I managed to compile a hello world example with no issues, but it throws exceptions and doesn't work
VANYA
Posts: 1834
Joined: Oct 24, 2010 15:16
Location: Ярославль
Contact:

Re: What happened to the Emscripten branch?

Post by VANYA »

Which version did you use? V1ctor's one, or CoderJeff's one? Also, what happens with a simple hello world example? Can you compile it? Can you run it?

I am using CoderJeff's version. I managed to compile a hello world example with no issues, but it throws exceptions and doesn't work
I use:

1) linux mint 19.3
2) emscripten 1.22.1-1build1 (by default in the standard repository)
3) compiler archive with emscripten from here: https://github.com/jayrm/fbc/tree/emscripten. When compiling it, a warning is displayed that the LLVM version must be older (I have a newer version), but the compiler and libraries are compiled. And when compiling the BAS source codes, problems appear (I described this above). Actually I tried the same archive from here: https://sourceforge.net/p/fbc/code/ci/emscripten/tree/ and tried to compile it with compiler version 1.05 (since at the time of creation freebasic-emscripten was version 1.05) , but couldn't even compile.
angros47
Posts: 2323
Joined: Jun 21, 2005 19:04

Re: What happened to the Emscripten branch?

Post by angros47 »

Can you compile a simple hello world in C using that version of emscripten? Because I tried installing it on Ubuntu 16 and 18 and it never worked. All the sites where I asked told me that version is outdated and not working (I asked on Stack Overflow too https://stackoverflow.com/questions/635 ... it-to-work). Since then I switched to the 64 bit version of the OS and installed the latest version of emscripten. I never managed to get version 1.22 to work.

So, write a simple hello world test in c, and compile it with emcc. If you can't get it to work, it means you are using a broken version of emcc, and you need to replace it if you want to experiment.
VANYA
Posts: 1834
Joined: Oct 24, 2010 15:16
Location: Ярославль
Contact:

Re: What happened to the Emscripten branch?

Post by VANYA »

I install the most recent version emscripten. I took the usual source "C" with "hello world".

The source is compiled, files are created: "1.js", "1.html".

When using the console with the command:
node 1.js
everything is displayed correctly in the terminal.

However, when using a browser with the 1.html file, nothing works, it just keeps "Preparing".


As for source code freebasic, an error pops up when compiling:
fbc -target js-asmjs 1.bas -v
FreeBASIC Compiler - Version 1.08.0 (2020-11-02), built for linux-x86_64 (64bit)
Copyright (C) 2004-2019 The FreeBASIC development team.
target: js-asmjs, asmjs, 32bit (js-asmjs)
backend: gcc
compiling: 1.bas -o 1.c (main module)
compiling C: emcc -S -nostdlib -nostdinc -Wall -Wno-unused-label -Wno-unused-function -Wno-unused-variable -Wno-warn-absolute-paths -s ASYNCIFY=1 -s RETAIN_COMPILER_SETTINGS=1 -Wno-main -Werror-implicit-function-declaration -fno-strict-aliasing -fno-math-errno -fwrapv -fno-exceptions -fno-unwind-tables -fno-asynchronous-unwind-tables -Wno-format "1.c" -o "1.llvm"
assembling: llvm-as "1.llvm" -o "1.o"
llvm-as: 1.llvm:1:2: error: expected top-level entity
.text
^
assembling failed: 'llvm-as' terminated with exit code 1
I'm tired of fighting ...
angros47
Posts: 2323
Joined: Jun 21, 2005 19:04

Re: What happened to the Emscripten branch?

Post by angros47 »

Unless you compiled it with the flag "-s WASM=0", you should have also the file 1.wasm, check if you have it.
And the reason why you can't get it to work in your browser is that javascript cannot access local files for security reasons, so it cannot load it completely. You need to start up a small local web server. You can do it with:

Code: Select all

python3 -m http.server
from the directory where you have your files, then with the browser you visit localhost:8000/1.html

It should work (I learned it in the harsh way, so I understand your struggles)

About the FreeBasic compiler, I had exactly the same error message you got. I managed to get rid of it by patching the compiler as I showed few posts ago. I still couldn't get a compiled file to work
VANYA
Posts: 1834
Joined: Oct 24, 2010 15:16
Location: Ярославль
Contact:

Re: What happened to the Emscripten branch?

Post by VANYA »

You need to start up a small local web server.
Yes, Emscripten is working, thanks!

However, we have not come close to working FreeBasic and Emscripten :(
angros47
Posts: 2323
Joined: Jun 21, 2005 19:04

Re: What happened to the Emscripten branch?

Post by angros47 »

When trying to compile with FreeBasic, try adding the flag -Wl "-s WASM=0" , as in

Code: Select all

fbc -target js-asmjs test.bas -Wl "-s WASM=0"
It will create a .js file, instead of a .wasm file. It's easier to debug
angros47
Posts: 2323
Joined: Jun 21, 2005 19:04

Re: What happened to the Emscripten branch?

Post by angros47 »

Ok, found one of the issues: in file src/rtlib/js/hinit.c , the lines

Code: Select all

	// keyboard
	emscripten_set_keypress_callback( 0, NULL, 1, fb_hKeyEventHandler );
	emscripten_set_keydown_callback( 0, NULL, 1, fb_hKeyEventHandler );
	emscripten_set_keyup_callback( 0, NULL, 1, fb_hKeyEventHandler );

	// mouse
	emscripten_set_mousemove_callback( 0, NULL, 1, fb_hMouseEventHandler );
	emscripten_set_mousedown_callback( 0, NULL, 1, fb_hMouseEventHandler );
	emscripten_set_mouseup_callback( 0, NULL, 1, fb_hMouseEventHandler );
	emscripten_set_dblclick_callback( 0, NULL, 1, fb_hMouseEventHandler );
must be replaced with:

Code: Select all

	// keyboard
	emscripten_set_keypress_callback( EMSCRIPTEN_EVENT_TARGET_WINDOW, NULL, 1, fb_hKeyEventHandler );
	emscripten_set_keydown_callback( EMSCRIPTEN_EVENT_TARGET_WINDOW, NULL, 1, fb_hKeyEventHandler );
	emscripten_set_keyup_callback( EMSCRIPTEN_EVENT_TARGET_WINDOW, NULL, 1, fb_hKeyEventHandler );

	// mouse
	emscripten_set_mousemove_callback( EMSCRIPTEN_EVENT_TARGET_WINDOW, NULL, 1, fb_hMouseEventHandler );
	emscripten_set_mousedown_callback( EMSCRIPTEN_EVENT_TARGET_WINDOW, NULL, 1, fb_hMouseEventHandler );
	emscripten_set_mouseup_callback( EMSCRIPTEN_EVENT_TARGET_WINDOW, NULL, 1, fb_hMouseEventHandler );
	emscripten_set_dblclick_callback( EMSCRIPTEN_EVENT_TARGET_WINDOW, NULL, 1, fb_hMouseEventHandler );
The reason is explained here: https://emscripten.org/docs/api_referen ... -html5-api :
0 or NULL: If building with the option -s DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR=1 (default), NULL denotes an invalid element. If building with legacy option -s DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR=0 (not recommended), a default element is chosen automatically based on the event type.
The library still used the format of an old version of Emscripten

After that change, it is possible to compile graphical programs for web pages (console mode programs don't work yet)
VANYA
Posts: 1834
Joined: Oct 24, 2010 15:16
Location: Ярославль
Contact:

Re: What happened to the Emscripten branch?

Post by VANYA »

Are you working with the modified fbc.bas file? I don't understand the syntax of git patches. Could you drop this patched fbc.bas file somewhere?
Post Reply