-
-
Notifications
You must be signed in to change notification settings - Fork 605
Porting Golang applications to OSv
Adrian Hesketh edited this page Mar 17, 2023
·
5 revisions
Starting with release 0.51 OSv fully supports running Golang applications. In order to run a Golang application on OSv it needs to be build as a shared library like so:
go build -a -buildmode=c-shared -o app.so app.go
The golang program has to export main function to be invoked as program entry by OSv like so in this Golang snippet:
package main
import (
"fmt"
"C"
)
//export GoMain
func GoMain() {
fmt.Println("Hello World!");
}
func main() {
}
Please see full example here.
To build OSv image with Golang app using capstan please see this example.
Golang applications use directly SYSCALL instructions to make system calls instead of libc and therefore there might still be some missing system calls in OSv. It is pretty trivial to add one as you can see in this source code.