├── Makefile ├── Makefile.uk ├── README.md ├── helloworld.go ├── kraft.cloud.yaml ├── kraft.yaml └── server.go /Makefile: -------------------------------------------------------------------------------- 1 | UK_ROOT ?= $(PWD)/.unikraft/unikraft 2 | UK_LIBS ?= $(PWD)/.unikraft/libs 3 | 4 | LIBS := $(UK_LIBS)/compiler-rt:$(UK_LIBS)/libunwind:$(UK_LIBS)/libgo:$(UK_LIBS)/musl:$(UK_LIBS)/lwip 5 | 6 | all: 7 | @$(MAKE) -C $(UK_ROOT) A=$(PWD) L=$(LIBS) 8 | 9 | $(MAKECMDGOALS): 10 | @$(MAKE) -C $(UK_ROOT) A=$(PWD) L=$(LIBS) $(MAKECMDGOALS) 11 | -------------------------------------------------------------------------------- /Makefile.uk: -------------------------------------------------------------------------------- 1 | $(eval $(call addgoapp,apphelloworldgo)) 2 | 3 | APPHELLOWORLDGO_SRCS-y += $(APPHELLOWORLDGO_BASE)/helloworld.go 4 | #APPHELLOWORLDGO_SRCS-y += $(APPHELLOWORLDGO_BASE)/server.go 5 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Unikraft Go "hello world" Application 2 | 3 | This application prints "hello world" using go. 4 | 5 | To configure, build and run this application you need to have [kraft](https://github.com/unikraft/kraft) installed. 6 | 7 | Configure the application: 8 | ``` 9 | kraft configure 10 | ``` 11 | 12 | Build the application: 13 | ``` 14 | kraft build 15 | ``` 16 | 17 | And finally, run the application: 18 | ``` 19 | kraft run -M 512 20 | ``` 21 | 22 | If you want to have more control, you can configure and run the application manually. 23 | 24 | To configure it with the desired features: 25 | ``` 26 | make menuconfig 27 | ``` 28 | 29 | Build the application: 30 | ``` 31 | make 32 | ``` 33 | 34 | Run the application: 35 | ``` 36 | sudo qemu-system-x86_64 \ 37 | -kernel build/helloworld-go_kvm-x86_64 \ 38 | -enable-kvm \ 39 | -m 1G \ 40 | -nographic 41 | 42 | ``` 43 | 44 | For more information about `kraft` type ```kraft -h``` or read the 45 | [documentation](http://docs.unikraft.org). 46 | -------------------------------------------------------------------------------- /helloworld.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | fmt.Println("hello world") 7 | } -------------------------------------------------------------------------------- /kraft.cloud.yaml: -------------------------------------------------------------------------------- 1 | specification: '0.5' 2 | name: helloworld-go 3 | unikraft: 4 | version: cloud 5 | kconfig: 6 | - CONFIG_LIBSYSCALL_SHIM_LIBCSTUBS=y 7 | - CONFIG_LIBPOSIX_MMAP=y 8 | - CONFIG_LIBUKSCHED=y 9 | - CONFIG_LIBUKSCHEDCOOP=y 10 | - CONFIG_STACK_SIZE_PAGE_ORDER=5 11 | targets: 12 | - name: kraftcloud-x86_64 13 | architecture: x86_64 14 | platform: firecracker 15 | kconfig: 16 | - CONFIG_PLAT_KVM=y 17 | - CONFIG_KVM_BOOT_PROTO_LXBOOT=y 18 | - CONFIG_KVM_VMM_FIRECRACKER=y 19 | - CONFIG_VIRTIO_BUS=y 20 | libraries: 21 | libgo: 22 | version: stable 23 | libunwind: 24 | version: stable 25 | compiler-rt: 26 | version: stable 27 | lwip: 28 | version: stable 29 | musl: 30 | version: stable 31 | ukp-bin: 32 | source: https://github.com/unikraft-io/lib-ukp-bin 33 | version: stable 34 | -------------------------------------------------------------------------------- /kraft.yaml: -------------------------------------------------------------------------------- 1 | specification: '0.5' 2 | name: helloworld-go 3 | unikraft: 4 | version: '0.6' 5 | kconfig: 6 | - CONFIG_LIBSYSCALL_SHIM_LIBCSTUBS=y 7 | targets: 8 | - architecture: x86_64 9 | platform: kvm 10 | libraries: 11 | gcc: '0.6' 12 | libgo: '0.6' 13 | pthread-embedded: '0.6' 14 | lwip: '0.6' 15 | compiler-rt: '0.6' 16 | libcxx: '0.6' 17 | libcxxabi: '0.6' 18 | libunwind: '0.6' 19 | libucontext: '0.6' 20 | newlib: '0.6' 21 | -------------------------------------------------------------------------------- /server.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "net/http" 6 | ) 7 | 8 | func hello(w http.ResponseWriter, req *http.Request) { 9 | 10 | fmt.Fprintf(w, "hello\n") 11 | } 12 | 13 | func headers(w http.ResponseWriter, req *http.Request) { 14 | 15 | for name, headers := range req.Header { 16 | for _, h := range headers { 17 | fmt.Fprintf(w, "%v: %v\n", name, h) 18 | } 19 | } 20 | } 21 | 22 | func main() { 23 | 24 | http.HandleFunc("/hello", hello) 25 | http.HandleFunc("/headers", headers) 26 | 27 | http.ListenAndServe(":8090", nil) 28 | } 29 | --------------------------------------------------------------------------------