diff --git a/example/go.mod b/example/go.mod new file mode 100644 index 0000000..4f52496 --- /dev/null +++ b/example/go.mod @@ -0,0 +1,3 @@ +module github.com/msanft/keystone-go-enclaves + +go 1.20 diff --git a/example/main.go b/example/main.go new file mode 100644 index 0000000..4f0e368 --- /dev/null +++ b/example/main.go @@ -0,0 +1,23 @@ +package main + +/* +#include +#include + +void myprint() { + printf("Hello world (c)\n)"); +} +*/ +import "C" +import "fmt" + +func main() { + C.myprint() + fmt.Println("Hello world (go)") +} + +// import "fmt" + +// func main() { +// fmt.Println("Hello world") +// } diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..204831f --- /dev/null +++ b/flake.lock @@ -0,0 +1,25 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1694343207, + "narHash": "sha256-jWi7OwFxU5Owi4k2JmiL1sa/OuBCQtpaAesuj5LXC8w=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "78058d810644f5ed276804ce7ea9e82d92bee293", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..7492ced --- /dev/null +++ b/flake.nix @@ -0,0 +1,39 @@ +{ + description = "A very basic flake"; + + outputs = { self, nixpkgs }: + let + pkgs = nixpkgs.legacyPackages.x86_64-linux; + musl = pkgs.pkgsCross.riscv64.musl; # pkgs.musl; + in + { + packages.x86_64-linux.default = pkgs.pkgsCross.riscv64.pkgsStatic.buildGoModule { + pname = "keystone-go-enclaves"; + version = "0.0.0"; + + src = ./example; + + vendorHash = null; + + nativeBuildInputs = [ musl ]; + + CGO_ENABLED = 1; + + ldflags = [ + "-s" + "-w" + "-linkmode external" + "-extldflags '-static -L${musl}/lib'" + ]; + + }; + + devShells.x86_64-linux.default = pkgs.mkShell + { + packages = [ + pkgs.qemu + musl + ]; + }; + }; +} diff --git a/result b/result new file mode 120000 index 0000000..e904b47 --- /dev/null +++ b/result @@ -0,0 +1 @@ +/nix/store/8j6v8fdwwb2lcmz1b6rqzsj9v0g0xzi4-keystone-go-enclaves-static-riscv64-unknown-linux-musl-0.0.0 \ No newline at end of file