Skip to content

Commit

Permalink
Initial support for building embedded ceph and calling it from a go cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
Bassam Tabbara committed Jul 25, 2016
1 parent b19e51f commit fa4dc4e
Show file tree
Hide file tree
Showing 10 changed files with 113 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
bin/
tools/
vendor/

1 change: 1 addition & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[submodule "ceph"]
path = ceph
url = [email protected]:quantum/ceph
branch = wip-embedded-ceph
Empty file added LICENSE
Empty file.
51 changes: 51 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Castle - Software Defined Storage

2 changes: 1 addition & 1 deletion ceph
Submodule ceph updated from c4da56 to d43b87
34 changes: 34 additions & 0 deletions cmd/castled/main.go
Original file line number Diff line number Diff line change
@@ -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()
}
12 changes: 12 additions & 0 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions glide.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package: github.com/quantum/castle
import:
- package: github.com/spf13/cobra
subpackages:
- cobra
3 changes: 3 additions & 0 deletions version/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package version

var Version = "0.0.0"

0 comments on commit fa4dc4e

Please sign in to comment.