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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wasm integration #47

Open
wants to merge 29 commits into
base: main
Choose a base branch
from
Open

Wasm integration #47

wants to merge 29 commits into from

Conversation

rogueloop
Copy link

@rogueloop rogueloop commented May 11, 2024

What type of MR is this? (check all applicable)

  • [ x] 馃崟 Feature

Web assembly integration for Lama2.

Modifying Golang to add support for building web assembly binary.

Important files to start review from

Controller.wasm.go
l2.wasm.go

lama2cmd/lama2cmd.wasm.go
preprocess/preprocess.wasm.go

Build command for normal cli builds

go build -tags=cli -o build/l2 -ldflags "-X main.version=$(git tag --sort=-version:refname | head -n 1) -X main.lamawasm=cli " l2.go

Build command for wasm builds

GOOS=js GOARCH=wasm go build -o build/l2.wasm -tags=wasm -ldflags "-X main.version=$(git tag --sort=-version:refname | head -n 1) -X main.lamawasm=lamawasm " l2.wasm.go

@@ -16,11 +16,11 @@ jobs:
- name: Install dependencies
run: go mod tidy
- name: Build
run: go build -v ./...
run: go build -tags=cli -v ./...
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this done only for ones with tag cli, are there any other tags

Copy link
Author

Choose a reason for hiding this comment

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

yes there is wasm tag also currently build is failing , checking that now

Comment on lines +58 to +59
keyValuePair := fmt.Sprintf("%s=%s", key, val.Data().(string))
command = append(command, keyValuePair)
Copy link
Contributor

Choose a reason for hiding this comment

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

Are these changes tested?

// TODO - replace stuff in headers, and varjson and json as well
cmd, stdinBody := cmdgen.ConstructCommand(block)
resp, e1 := cmdexec.ExecCommand(cmd, stdinBody)
printFields(resp)
Copy link
Contributor

Choose a reason for hiding this comment

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

What does this do

Copy link
Author

Choose a reason for hiding this comment

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

Added it for debugging purpose, printing the response

l2.wasm.go Outdated
Comment on lines 24 to 26
js.Global().Set("lama2Wasm", js.FuncOf(lama2Wasm))
js.Global().Set("goWebRequestFunc", wasmLamaPromise())
select {}
Copy link
Contributor

Choose a reason for hiding this comment

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

Can add a comment on what these lines do

l2.wasm.go Outdated

func lama2Wasm(this js.Value, i []js.Value) interface{} {
go func() {
controller.ProcessWasmInput("GET\nhttps://httpbin.org/get")
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this for processing the Default request?

Copy link
Author

Choose a reason for hiding this comment

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

That function was for testing purpose , removed

@@ -6,7 +6,7 @@ import (

"github.com/HexmosTech/lama2/l2lsp/request"
"github.com/HexmosTech/lama2/l2lsp/response"
"github.com/rs/zerolog/log"
// "github.com/rs/zerolog/log"
Copy link
Contributor

Choose a reason for hiding this comment

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

This can be removed right

Copy link
Author

Choose a reason for hiding this comment

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

this is for logging purpose


func ExpandHeaders(block *gabs.Container) {
headerMap := block.S("details", "headers")
// log.Info().Str("HeaderMap", headerMap.String()).Msg("")
Copy link
Contributor

Choose a reason for hiding this comment

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

Can remove commented code

@@ -0,0 +1,220 @@
//go:build wasm
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the basic difference in the code between preprocess.wasm.go and preprocess.go

Copy link
Author

Choose a reason for hiding this comment

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

there is a lot of code repetition there converted it into 3 separate file to remove duplication

Copy link
Author

Choose a reason for hiding this comment

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

The difference is in function calls , wasm has 1 parameter , cli has 2 params , each of them calls different functions

Copy link
Contributor

Choose a reason for hiding this comment

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

Why is the wasm file aswell pushed to the repo?

Copy link
Contributor

Choose a reason for hiding this comment

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

Cant the doc site use the injector or something?

Copy link
Contributor

Choose a reason for hiding this comment

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

Cant the doc site use the injector or something?

Copy link
Contributor

Choose a reason for hiding this comment

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

One more bin here both 24mb

func ExecCommand(cmdSlice []string, stdinBody string) (httpie.ExResponse, error) {
proxyURL := "https://proxyserver.hexmos.com/"
proxyUserName := "proxyServer"
proxyUserPassword := "proxy22523146server"
Copy link
Contributor

Choose a reason for hiding this comment

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

Passwords are open, variables are not declared for the URL, name, password. Is the password meant to be open?

@lovestaco
Copy link
Contributor

lovestaco commented May 25, 2024

Too many files need an abstract PR description, like

  1. A wasm bin is generated
  2. The bin starts from funcname() from filename.ext
  3. Moves to blah for doing X
  4. Moves to blah2 for doing Y

It would be better to write in this way, so that when you're writing documentation you can reuse this and iterate on that.

Plus points if you put it in a mermaid diagram

It'll be more easy for you later on

Because if you do 1 month marketing, you only will forget the flow :D

js.Global().Call("eval", jsCode)
}

func GenerateChainCode(httpRespBody string) string {

Choose a reason for hiding this comment

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

can you add a comment on what this function is doing? what is generate chain code?

"github.com/HexmosTech/gabs/v2"
)

func assembleCmdString(httpv string, url string, jsonObj *gabs.Container, headers *gabs.Container, multipart bool, form bool) ([]string, string) {

Choose a reason for hiding this comment

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

add a comment about what is this function doing

// UpdateSelf downloads the installation script from
// the official repository, and executes it to update
// the l2 binary to the latest version
func UpdateSelf() {

Choose a reason for hiding this comment

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

is this function for a self-update wasm file or a L2 binary?

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.

None yet

5 participants