Initial support for building embedded ceph and calling it from a go cmd

This commit is contained in:
Bassam Tabbara
2016-07-24 22:27:07 -07:00
parent b19e51fd5b
commit fa4dc4e406
10 changed files with 113 additions and 1 deletions
+4
View File
@@ -0,0 +1,4 @@
bin/
tools/
vendor/
+1
View File
@@ -1,3 +1,4 @@
[submodule "ceph"]
path = ceph
url = git@github.com:quantum/ceph
branch = wip-embedded-ceph
View File
+51
View File
@@ -0,0 +1,51 @@
ifeq ($(origin VERSION), undefined)
VERSION != git describe --dirty --always
endif
REPOPATH = github.com/quantum/castle
GOOS=$(shell go env GOOS)
GOARCH=$(shell go env GOARCH)
NPROCS:=1
ifeq ($(GOOS),linux)
NPROCS:=$(shell grep -c ^processor /proc/cpuinfo)
endif
build: vendor ceph/build/lib/libcephd.a
@for i in castled; do \
go build -o bin/$$i -installsuffix cgo -ldflags "-extldflags '-static' -linkmode external -X $(REPOPATH)/version.Version=$(VERSION)" ./cmd/$$i; \
done
ceph/build/Makefile:
git submodule update --init --recursive
cd ceph && ./do_cmake.sh -DWITH_EMBEDDED=ON -DWITH_FUSE=OFF
ceph/build/lib/libcephd.a: ceph/build/Makefile
cd ceph/build && make -j$(NPROCS) cephd
test: tools/glide
go test --race $(shell ./tools/glide novendor)
vet: tools/glide
go vet $(shell ./tools/glide novendor)
fmt: tools/glide
go fmt $(shell ./tools/glide novendor)
clean:
rm -rf ./bin
cd ceph/build && make clean
cleanall: clean
rm -rf bin tools vendor
vendor: tools/glide
./tools/glide install
tools/glide:
@echo "Downloading glide"
mkdir -p tools
curl -L https://github.com/Masterminds/glide/releases/download/v0.11.1/glide-v0.11.1-$(GOOS)-$(GOARCH).tar.gz | tar -xz -C tools
mv tools/$(GOOS)-$(GOARCH)/glide tools/glide
rm -r tools/$(GOOS)-$(GOARCH)
+2
View File
@@ -0,0 +1,2 @@
# Castle - Software Defined Storage
+1 -1
Submodule ceph updated: c4da56d0cb...d43b87b166
+34
View File
@@ -0,0 +1,34 @@
package main
// #cgo CFLAGS: -I${SRCDIR}/../../ceph/src/include
// #cgo LDFLAGS: -L${SRCDIR}/../../ceph/build/lib -lcephd -lstdc++
// #include "cephd/libcephd.h"
import "C"
import (
"fmt"
"github.com/quantum/castle/version"
"github.com/spf13/cobra"
)
func CephVersion() (string) {
var c_major, c_minor, c_patch C.int
return C.GoString(C.ceph_version(&c_major,&c_minor,&c_patch))
}
func main() {
var cmdVersion = &cobra.Command{
Use: "version",
Short: "print castle version",
Long: `prints the version of castle.`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("castled version %v (ceph version %v)\n", version.Version, CephVersion())
},
}
var rootCmd = &cobra.Command{Use: "castled"}
rootCmd.AddCommand(cmdVersion)
rootCmd.Execute()
}
Generated
+12
View File
@@ -0,0 +1,12 @@
hash: ed0ac78e36a48a3140bd61be5aba1db8f7a7b3adae518dd6419a49ff46af4424
updated: 2016-07-24T13:00:22.18839951-07:00
imports:
- name: github.com/inconshreveable/mousetrap
version: 76626ae9c91c4f2a10f34cad8ce83ea42c93bb75
- name: github.com/spf13/cobra
version: dbb7c2d02e284aa24423e3e6e105969dffe6e4d6
subpackages:
- cobra
- name: github.com/spf13/pflag
version: 1560c1005499d61b80f865c04d39ca7505bf7f0b
testImports: []
+5
View File
@@ -0,0 +1,5 @@
package: github.com/quantum/castle
import:
- package: github.com/spf13/cobra
subpackages:
- cobra
+3
View File
@@ -0,0 +1,3 @@
package version
var Version = "0.0.0"