MotleyCoderDev / wasm2brs

Bringing the power of WebAssembly to the Roku and supporting languages like C/C++/Rust.
https://motley-coder.com/2020/12/20/webassembly-on-roku/
Other
50 stars 5 forks source link

Duplicate functions in Rust sample #5

Open iBicha opened 1 year ago

iBicha commented 1 year ago
------ Compiling dev 'Rust' ------
*** ERROR compiling pkg:/source/rust-wasm.out.brs:
SUB or FUNCTION defined twice. (compile error &had) in pkg:/source/rust-wasm.out.brs(163) 'w2b__start'

=================================================================
An error occurred while attempting to compile the application's components:
-------> Compilation Failed.
pkg:/source/rust-wasm.out.brs
SUB or FUNCTION defined twice. (compile error &had) in pkg:/source/rust-wasm.out.brs(163) 'w2b__start'

Did this sample used to function? I'm trying to figure out why this is happening

TrevorSundberg commented 1 year ago

Hmm, can you post the built file? Also just make sure you don't have any other .brs files in there with a w2b__start function defined

iBicha commented 1 year ago

Yeah I can see w2b__start twice in the generated code. In another test where I had two functions (main and another one) both were duplicated.

rust-wasm.out.brs.zip

TrevorSundberg commented 1 year ago

It looks like something might have changed with the rust compiler and it's now exporting functions with the same names. Most likely a problem with wasm2brs where it needs to check export names or pre-pend something. I believe you can remove the following lines from your file:

' export: 'w2b' '' '_start'
Function w2b__start()
  Return w2b__start_command_export_1562511516()
End Function
' export: 'w2b' '' 'main'
Function w2b_main(p0 As Integer, p1 As Integer)
  Return w2b_main_command_export_1255868340(p0, p1)
End Function

Those generated functions seem to be only there for exports. I'll have to spend a bit of time going back through and understanding why this is, but for now hopefully that can unblock you (obviously gross having to delete that every time).