Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Wasm #163

Merged
merged 10 commits into from
Jan 2, 2025
Merged

Support Wasm #163

merged 10 commits into from
Jan 2, 2025

Conversation

@fiatjaf
Copy link
Collaborator

fiatjaf commented Jan 2, 2025

I always wanted to do this, thank you! So really the only part that was needed was the WebSocket connection and you just did it?

@@ -1,4 +1,4 @@
//go:build !sqlite_math_functions
//go:build !js && !sqlite_math_functions
Copy link
Collaborator

@fiatjaf fiatjaf Jan 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't this mean it will compile this test when js is true but sqlite_math_functions is false or vice-versa? shouldn't it be ||? (I really don't know)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This means js is false and sqlite_math_functions is false, I guess.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So if one of them is true this will be compiled, which is not what we want.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to be working as expected:

20:47 sdk/hints/test wasm $ GOOS=js GOARCH=wasm go test -run TestSQLiteHintsLibsql
testing: warning: no tests to run
PASS
ok      github.com/nbd-wtf/go-nostr/sdk/hints/test      1.115s
20:47 sdk/hints/test wasm $ go test -tags sqlite_math_functions -run TestSQLiteHintsLibsql
testing: warning: no tests to run
PASS
ok      github.com/nbd-wtf/go-nostr/sdk/hints/test      0.289s
20:47 sdk/hints/test wasm $ go test -run TestSQLiteHintsLibsql
= print scores
== relay scores for 0000000000000000000000000000000000000000000000000000000000000001
    0 ::                  wss://bbb.net ::>        59616
    1 ::                  wss://aaa.com ::>        57245
= print scores
== relay scores for 0000000000000000000000000000000000000000000000000000000000000001
    0 ::                  wss://bbb.net ::>        59616
    1 ::                  wss://ccc.org ::>        20930
    2 ::                  wss://aaa.com ::>     -1437816
= print scores
== relay scores for 0000000000000000000000000000000000000000000000000000000000000001
    0 ::                  wss://bbb.net ::>        59616
    1 ::                  wss://aaa.com ::>     -1437816
    2 ::                  wss://ccc.org ::>     -1459181
= print scores
== relay scores for 0000000000000000000000000000000000000000000000000000000000000001
    0 ::                  wss://bbb.net ::>        59616
    1 ::                  wss://aaa.com ::>     -1425031
    2 ::                  wss://ccc.org ::>     -1459181
= print scores
== relay scores for 0000000000000000000000000000000000000000000000000000000000000001
    0 ::                  wss://bbb.net ::>        59616
    1 ::                  wss://aaa.com ::>     -1425031
    2 ::                  wss://ccc.org ::>     -1459181
== relay scores for 0000000000000000000000000000000000000000000000000000000000000002
    0 ::                  wss://ccc.org ::>       125585
    1 ::                  wss://aaa.com ::>        19370
    2 ::                  wss://bbb.net ::>        19370
= print scores
== relay scores for 0000000000000000000000000000000000000000000000000000000000000001
    0 ::                  wss://bbb.net ::>        59616
    1 ::                  wss://aaa.com ::>     -1425031
    2 ::                  wss://ccc.org ::>     -1459181
== relay scores for 0000000000000000000000000000000000000000000000000000000000000002
    0 ::                  wss://ccc.org ::>       125585
    1 ::                  wss://aaa.com ::>        19370
    2 ::                  wss://bbb.net ::>        19370
== relay scores for 0000000000000000000000000000000000000000000000000000000000000003
    0 ::                  wss://bbb.net ::>        20190
    1 ::                  wss://aaa.com ::>         4583
= print scores
== relay scores for 0000000000000000000000000000000000000000000000000000000000000001
    0 ::                  wss://bbb.net ::>        59616
    1 ::                  wss://aaa.com ::>     -1425031
    2 ::                  wss://ccc.org ::>     -1459181
== relay scores for 0000000000000000000000000000000000000000000000000000000000000002
    0 ::                  wss://ccc.org ::>       125585
    1 ::                  wss://aaa.com ::>        19370
    2 ::                  wss://bbb.net ::>        19370
== relay scores for 0000000000000000000000000000000000000000000000000000000000000003
    0 ::                  wss://aaa.com ::>      -403324
    1 ::                  wss://bbb.net ::>     -1444050
= print scores
== relay scores for 0000000000000000000000000000000000000000000000000000000000000001
    0 ::                  wss://bbb.net ::>        59616
    1 ::                  wss://aaa.com ::>     -1425031
    2 ::                  wss://ccc.org ::>     -1459181
== relay scores for 0000000000000000000000000000000000000000000000000000000000000002
    0 ::                  wss://ccc.org ::>       125585
    1 ::                  wss://aaa.com ::>        19370
    2 ::                  wss://bbb.net ::>        19370
== relay scores for 0000000000000000000000000000000000000000000000000000000000000003
    0 ::                  wss://aaa.com ::>      -403324
    1 ::                  wss://bbb.net ::>     -1444050
== relay scores for 0000000000000000000000000000000000000000000000000000000000000004
    0 ::                  wss://aaa.com ::>       115904
    1 ::                  wss://bbb.net ::>       110716
= print scores
== relay scores for 0000000000000000000000000000000000000000000000000000000000000001
    0 ::                  wss://bbb.net ::>        59616
    1 ::                  wss://aaa.com ::>     -1425031
    2 ::                  wss://ccc.org ::>     -1459181
== relay scores for 0000000000000000000000000000000000000000000000000000000000000002
    0 ::                  wss://ccc.org ::>       125585
    1 ::                  wss://aaa.com ::>        19370
    2 ::                  wss://bbb.net ::>        19370
== relay scores for 0000000000000000000000000000000000000000000000000000000000000003
    0 ::                  wss://aaa.com ::>      -403324
    1 ::                  wss://bbb.net ::>     -1444050
== relay scores for 0000000000000000000000000000000000000000000000000000000000000004
    0 ::                  wss://aaa.com ::>       115904
    1 ::                  wss://bbb.net ::>       110716
    2 ::                  wss://ccc.org ::>         7446
= print scores
== relay scores for 0000000000000000000000000000000000000000000000000000000000000001
    0 ::                  wss://bbb.net ::>        59616
    1 ::                  wss://aaa.com ::>     -1425031
    2 ::                  wss://ccc.org ::>     -1459181
== relay scores for 0000000000000000000000000000000000000000000000000000000000000002
    0 ::                  wss://ccc.org ::>       125585
    1 ::                  wss://aaa.com ::>        19370
    2 ::                  wss://bbb.net ::>        19370
== relay scores for 0000000000000000000000000000000000000000000000000000000000000003
    0 ::                  wss://aaa.com ::>      -403324
    1 ::                  wss://bbb.net ::>     -1444050
== relay scores for 0000000000000000000000000000000000000000000000000000000000000004
    0 ::                  wss://ccc.org ::>         7446
    1 ::                  wss://aaa.com ::>     -1294495
    2 ::                  wss://bbb.net ::>     -1299683
= print scores
== relay scores for 0000000000000000000000000000000000000000000000000000000000000001
    0 ::                  wss://bbb.net ::>        59616
    1 ::                  wss://aaa.com ::>     -1425031
    2 ::                  wss://ccc.org ::>     -1459181
== relay scores for 0000000000000000000000000000000000000000000000000000000000000002
    0 ::                  wss://ccc.org ::>       125585
    1 ::                  wss://aaa.com ::>        19370
    2 ::                  wss://bbb.net ::>        19370
== relay scores for 0000000000000000000000000000000000000000000000000000000000000003
    0 ::                  wss://aaa.com ::>      -403324
    1 ::                  wss://bbb.net ::>     -1444050
== relay scores for 0000000000000000000000000000000000000000000000000000000000000004
    0 ::                  wss://aaa.com ::>       680064
    1 ::                  wss://bbb.net ::>       674876
    2 ::                  wss://ccc.org ::>         7446
= print scores
== relay scores for 0000000000000000000000000000000000000000000000000000000000000001
    0 ::                  wss://bbb.net ::>        59616
    1 ::                  wss://aaa.com ::>     -1425031
    2 ::                  wss://ccc.org ::>     -1459181
== relay scores for 0000000000000000000000000000000000000000000000000000000000000002
    0 ::                  wss://ccc.org ::>       125585
    1 ::                  wss://aaa.com ::>        19370
    2 ::                  wss://bbb.net ::>        19370
== relay scores for 0000000000000000000000000000000000000000000000000000000000000003
    0 ::                  wss://aaa.com ::>      -403324
    1 ::                  wss://bbb.net ::>     -1444050
== relay scores for 0000000000000000000000000000000000000000000000000000000000000004
    0 ::                  wss://ccc.org ::>      1516650
    1 ::                  wss://aaa.com ::>       680064
    2 ::                  wss://bbb.net ::>       674876
PASS
ok      github.com/nbd-wtf/go-nostr/sdk/hints/test      0.432s
20:48 sdk/hints/test wasm $ GOOS=js GOARCH=wasm go test -tags sqlite_math_functions -run TestSQLiteHintsLibsql
testing: warning: no tests to run
PASS
ok      github.com/nbd-wtf/go-nostr/sdk/hints/test      0.724s

@1l0
Copy link
Contributor Author

1l0 commented Jan 2, 2025

That's lovely to hear. Yeah, just as you wrote. But I'm not sure whether there could be edge cases that fail.

@1l0
Copy link
Contributor Author

1l0 commented Jan 2, 2025

And this doesn't support TinyGo unfortunately. At least github.com/puzpuzpuz/xsync uses newer RWMutex method which TinyGo doesn't support.

@fiatjaf
Copy link
Collaborator

fiatjaf commented Jan 2, 2025

And this doesn't support TinyGo unfortunately.

Oh, this is sad. Maybe we can work on removing these dependencies. I'll try that later.

@fiatjaf fiatjaf merged commit 63919cf into nbd-wtf:master Jan 2, 2025
1 check passed
@fiatjaf
Copy link
Collaborator

fiatjaf commented Jan 2, 2025

I can't run any of these tests. What am I doing wrong?

~> GOOS=js GOARCH=wasm go test -run TestSQLiteHintsLibsql
fork/exec /tmp/go-build2062213332/b001/go-nostr.test: exec format error
FAIL	github.com/nbd-wtf/go-nostr	0.004s

@1l0
Copy link
Contributor Author

1l0 commented Jan 2, 2025

Did you rename wasmbrowsertest to go_js_wasm_exec?
https://github.com/agnivade/wasmbrowsertest?tab=readme-ov-file#quickstart

@1l0 1l0 deleted the wasm branch January 3, 2025 07:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants