Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ target/
*.so
*.dylib
*.h
*.wasm

*.test

Expand Down
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ build-native-cross-platform:
go install src.techknowlogick.com/xgo@latest
xgo $(COMMON_BUILD_ARGS) -out native/out/helm --targets */arm64,*/amd64 ./native

.PHONY: build-native-wasi
build-native-wasi:
#cd native && GOOS=wasip1 GOARCH=wasm go build -o ./out/helm.wasm ./wasm/main.go
# Andrea recommends using TinyGo
# Doesn't work, need to find the right combination of ENV variables
#cd native && GOOS=wasip1 GOARCH=wasm tinygo build -o ./out/helm.wasm
# Working Version:
cd native && tinygo build -target=wasi -o ./out/helm.wasm ./wasm/main.go

.PHONY: build-java
build-java:
mvn $(MAVEN_OPTIONS) clean verify
Expand Down
72 changes: 72 additions & 0 deletions native/wasm/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Copyright 2024 Marc Nuri
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package main

/*
#include <stdbool.h>
#include <stdlib.h>

typedef struct {
char* out;
char* err;
char* stdOut;
char* stdErr;
} Result;
*/
import "C"
import (
"fmt"
"strings"
"unsafe"
)

//export ExportedFunction
func ExportedFunction() int64 {
fmt.Println("Hello")
return 0
}

//export CString
func CString() *C.char {
return C.CString("A C String")
}

//export CFree
func CFree(pointer unsafe.Pointer) {
C.free(pointer)
}

//export CExport
func CExport() *C.Result {
return &C.Result{
out: toCString("out-string"),
err: toCString("err-string"),
stdOut: toCString("stdOut-string"),
stdErr: toCString("stdErr-string"),
}
}

func toCString(str string) *C.char {
if len(strings.TrimSpace(str)) == 0 {
return nil
}
return C.CString(str)
}

// Needed for compilation (only)
func main() {
}
Loading