diff --git a/.gitignore b/.gitignore index ee61c2e..0718b94 100644 --- a/.gitignore +++ b/.gitignore @@ -16,6 +16,8 @@ /annotations/out /examples/c-simple/bin /examples/c-simple/build +/examples/go-simple/bin +/examples/go-simple/build /examples/rust-simple/Cargo.lock /examples/rust-simple/bin /examples/rust-simple/build diff --git a/build.gradle b/build.gradle index 81622d8..2d6e003 100644 --- a/build.gradle +++ b/build.gradle @@ -99,6 +99,31 @@ project(':examples') { } } + // Go example helpers + + task goToWasm { + doFirst { + mkdir 'build' + exec { + def goFileName = fileTree(dir: '.', includes: ['*.go']).files.iterator().next() + environment 'GOOS': 'js', 'GOARCH': 'wasm' + commandLine 'go', 'build', '-o', 'build/lib.wasm', goFileName + } + } + } + + task compileGoWasm(type: JavaExec) { + dependsOn goToWasm + classpath configurations.compileClasspath + main = 'asmble.cli.MainKt' + doFirst { + // args 'help', 'compile' + def outFile = 'build/wasm-classes/' + wasmCompiledClassName.replace('.', '/') + '.class' + file(outFile).parentFile.mkdirs() + args 'compile', 'build/lib.wasm', wasmCompiledClassName, '-out', outFile, '-log', 'debug' + } + } + // Rust example helpers ext.rustBuildRelease = true @@ -160,6 +185,18 @@ project(':examples:c-simple') { mainClassName = 'asmble.examples.csimple.Main' } +project(':examples:go-simple') { + apply plugin: 'application' + ext.wasmCompiledClassName = 'asmble.generated.GoSimple' + dependencies { + compile files('build/wasm-classes') + } + compileJava { + dependsOn compileGoWasm + } + mainClassName = 'asmble.examples.gosimple.Main' +} + project(':examples:rust-regex') { apply plugin: 'application' apply plugin: 'me.champeau.gradle.jmh' diff --git a/examples/go-simple/simple.go b/examples/go-simple/simple.go new file mode 100644 index 0000000..687fa85 --- /dev/null +++ b/examples/go-simple/simple.go @@ -0,0 +1,10 @@ +package main + +import ( + "fmt" + "os" +) + +func main() { + fmt.Printf("Args: %v", os.Args) +} diff --git a/settings.gradle b/settings.gradle index edd9a86..3b6175d 100644 --- a/settings.gradle +++ b/settings.gradle @@ -2,6 +2,7 @@ rootProject.name = 'asmble' include 'annotations', 'compiler', 'examples:c-simple', + 'examples:go-simple', 'examples:rust-regex', 'examples:rust-simple', 'examples:rust-string' \ No newline at end of file