| SHELL := /bin/bash -euo pipefail |
| PWD := $(shell pwd) |
| V23_GOPATH := $(shell echo `v23 run env | grep GOPATH | cut -d\= -f2`) |
| DART_FILES := $(shell find dart/bin dart/lib dart/test -name "*.dart" -not -path "dart/lib/gen/*") |
| GO_FILES := $(shell find go/src -name "*.go") |
| V23_GO_FILES := $(shell find $(V23_ROOT) -name "*.go") |
| |
| # Flags for Syncbase service running as Mojo service. |
| # See v.io/x/ref/runtime/internal/mojo_util.go for the wonderful magic that |
| # makes this work. |
| SYNCBASED_ADDR := 127.0.0.1:4002 |
| V23_MOJO_FLAGS := --v=5 --alsologtostderr=false --root-dir=/tmp/syncbase_mojo --v23.tcp.address=$(SYNCBASED_ADDR) --v23.permissions.literal={"Admin":{"In":["..."]},"Write":{"In":["..."]},"Read":{"In":["..."]},"Resolve":{"In":["..."]},"Debug":{"In":["..."]}} --v23.credentials=$(V23_ROOT)/experimental/projects/ether/creds |
| |
| #MOUNTTABLE_ADDR := 127.0.0.1:4001 |
| ifdef MOUNTTABLE_ADDR |
| V23_MOJO_FLAGS += --name=syncbase_mojo --v23.namespace.root=/$(MOUNTTABLE_ADDR) |
| endif |
| |
| # Wrap the env var value in single quotes. Note, shell parsing works correctly |
| # because the value itself does not contain single quotes. |
| V23_MOJO_FLAGS := '$(V23_MOJO_FLAGS)' |
| |
| ifndef MOJO_DIR |
| $(error MOJO_DIR is not set) |
| endif |
| |
| ifndef V23_ROOT |
| $(error V23_ROOT is not set) |
| endif |
| |
| # NOTE(nlacasse): Running Go Mojo services requires passing the |
| # --enable-multiprocess flag to mojo_shell. This is because the Go runtime is |
| # very large, and can interfere with C++ memory if they are in the same |
| # process. |
| MOJO_SHELL_FLAGS := -v --enable-multiprocess |
| |
| ifdef ANDROID |
| # TODO(nlacasse): Serve mojo resources over HTTP so they are accessible to |
| # Android. Currently everything is served off the local filesystem, which |
| # will not work on Android. Until then, Android support is disabled. |
| $(error Android is currently not supported.) |
| |
| # Configure compiler and linker for Android. |
| GO_BIN := $(MOJO_DIR)/src/third_party/go/tool/android_arm/bin/go |
| GO_FLAGS := -tags=mojo -ldflags=-shared |
| |
| MOJO_ANDROID_FLAGS := --android |
| MOJO_BUILD_DIR := $(MOJO_DIR)/src/out/android_Debug |
| MOJO_SHARED_LIB := $(PWD)/gen/lib/android/libsystem_thunk.a |
| |
| SYNCBASE_LEVELDB_DIR := $(V23_ROOT)/third_party/cout/linux_amd64/leveldb |
| SYNCBASE_SNAPPY_DIR := $(V23_ROOT)/third_party/cout/linux_amd64/snappy |
| else |
| # Configure compiler and linker for Linux. |
| GO_BIN := $(MOJO_DIR)/src/third_party/go/tool/linux_amd64/bin/go |
| GO_FLAGS := -tags=mojo -ldflags=-shared -buildmode=c-shared |
| |
| MOJO_BUILD_DIR := $(MOJO_DIR)/src/out/Debug |
| MOJO_SHARED_LIB := $(PWD)/gen/lib/linux_amd64/libsystem_thunk.a |
| |
| # TODO(nlacasse): Build leveldb and snappy libs for android, and put the |
| # correct paths below. |
| SYNCBASE_LEVELDB_DIR := $(V23_ROOT)/third_party/cout/linux_amd64/leveldb |
| SYNCBASE_SNAPPY_DIR := $(V23_ROOT)/third_party/cout/linux_amd64/snappy |
| endif |
| |
| # Compiles a Go program and links against the Mojo C shared library. |
| # $1 is input filename. |
| # $2 is output filename. |
| # See $(MOJO_DIR)/mojo/go/go.py for description of arguments to go.py (aka |
| # MOGO_BIN). |
| # |
| # MOJO_GOPATH must be exported so it can be picked up by MOGO_BIN. |
| export MOJO_GOPATH := $(V23_GOPATH):$(PWD)/gen/go:$(PWD)/go:$(MOJO_BUILD_DIR)/gen/go |
| # TODO(nlacasse): It's strange that go.py takes CGO_CFLAGS and CGO_LDFLAGS as |
| # arguments, but other cgo settings (like CGO_CXXFLAGS) must be set with env |
| # variables. I think these should all be env variables. |
| export CGO_CXXFLAGS := -I$(SYNCBASE_LEVELDB_DIR)/include -I$(SYNCBASE_SNAPPY_DIR)/include |
| MOGO_BIN := $(MOJO_DIR)/src/mojo/go/go.py |
| define MOGO_BUILD |
| mkdir -p $(dir $2) |
| $(MOGO_BIN) $(MOJO_ANDROID_FLAGS) -- \ |
| "$(GO_BIN)" \ |
| "$(shell mktemp -d)" \ |
| "$(PWD)/$(2)" \ |
| "$(MOJO_DIR)/src" \ |
| "$(PWD)/gen" \ |
| "-I$(MOJO_DIR)/src -I$(SYNCBASE_LEVELDB_DIR)/include -I$(SYNCBASE_SNAPPY_DIR)/include" \ |
| "-L$(dir $(MOJO_SHARED_LIB)) -lsystem_thunk -L$(SYNCBASE_LEVELDB_DIR)/lib -L$(SYNCBASE_SNAPPY_DIR)/lib" \ |
| build $(GO_FLAGS) $1 |
| endef |
| |
| # Generates go bindings from .mojom file. |
| # $1 is input filename. |
| # $2 is output directory. |
| # $3 is language (go, dart, ...). |
| MOJOM_BIN := $(MOJO_DIR)/src/mojo/public/tools/bindings/mojom_bindings_generator.py |
| define MOJOM_GEN |
| mkdir -p $2 |
| $(MOJOM_BIN) $1 -d . -o $2 -g $3 |
| endef |
| |
| .DELETE_ON_ERROR: |
| |
| all: test |
| |
| # Builds mounttabled, principal, and syncbased. |
| bin: $(V23_GO_FILES) |
| v23 go build -a -o $@/mounttabled v.io/x/ref/services/mounttable/mounttabled |
| v23 go build -a -o $@/principal v.io/x/ref/cmd/principal |
| v23 go build -a -o $@/syncbased v.io/syncbase/x/ref/services/syncbase/syncbased |
| touch $@ |
| |
| # Mints credentials. |
| creds: bin |
| ./bin/principal seekblessings --v23.credentials creds |
| touch $@ |
| |
| # Builds the shared library that Mojo services must be linked with. |
| $(MOJO_SHARED_LIB): |
| ifeq ($(wildcard $(MOJO_BUILD_DIR)),) |
| $(error ERROR: $(MOJO_BUILD_DIR) does not exist. Please see README.md for instructions on compiling Mojo resources.) |
| endif |
| mkdir -p $(dir $@) |
| ar rcs $@ $(MOJO_BUILD_DIR)/obj/mojo/public/platform/native/system.system_thunks.o |
| |
| .PHONY: gen-mojom |
| # TODO(nlacasse): The echo_client and echo_server are currently used to test |
| # compilation and mojom binding generation. We should remove them once they |
| # are no longer needed. |
| gen-mojom: dart/lib/gen/dart-pkg/mojom/lib/mojo/echo.mojom.dart gen/go/src/mojom/echo/echo.mojom.go |
| gen-mojom: dart/lib/gen/dart-pkg/mojom/lib/mojo/syncbase.mojom.dart gen/go/src/mojom/syncbase/syncbase.mojom.go |
| |
| dart/lib/gen/dart-pkg/mojom/lib/mojo/echo.mojom.dart: mojom/echo.mojom |
| $(call MOJOM_GEN,$<,dart/lib/gen,dart) |
| # TODO(nlacasse): Figure out why mojom_bindings_generator creates these bad |
| # symlinks on dart files. |
| rm -f dart/lib/gen/mojom/echo.mojom.dart |
| |
| dart/lib/gen/dart-pkg/mojom/lib/mojo/syncbase.mojom.dart: mojom/syncbase.mojom |
| $(call MOJOM_GEN,$<,dart/lib/gen,dart) |
| # TODO(nlacasse): Figure out why mojom_bindings_generator creates these bad |
| # symlinks on dart files. |
| rm -f dart/lib/gen/mojom/syncbase.mojom.dart |
| |
| gen/go/src/mojom/echo/echo.mojom.go: mojom/echo.mojom |
| $(call MOJOM_GEN,$<,gen,go) |
| gofmt -w $@ |
| |
| gen/go/src/mojom/syncbase/syncbase.mojom.go: mojom/syncbase.mojom |
| $(call MOJOM_GEN,$<,gen,go) |
| gofmt -w $@ |
| |
| gen/mojo/echo_server.mojo: $(GO_FILES) $(MOJO_SHARED_LIB) gen/go/src/mojom/echo/echo.mojom.go |
| $(call MOGO_BUILD,$(PWD)/go/src/echo_server.go,$@) |
| |
| gen/mojo/syncbase_server.mojo: $(GO_FILES) $(V23_GO_FILES) $(MOJO_SHARED_LIB) gen/go/src/mojom/syncbase/syncbase.mojom.go |
| $(call MOGO_BUILD,v.io/syncbase/x/ref/services/syncbase/syncbased,$@) |
| |
| # Formats dart files to follow dart style conventions. |
| .PHONY: dartfmt |
| dartfmt: |
| dartfmt --overwrite --line-length 120 $(DART_FILES) |
| |
| # Lints src and test files with dartanalyzer. This takes a few seconds. |
| .PHONY: dartanalyzer |
| dartanalyzer: dart/packages gen-mojom |
| # TODO(nlacasse): Fix dart mojom binding generator so it does not produce |
| # files that violate dartanalyzer. For now, we use "grep -v" to hide all |
| # warnings from *.mojom.dart files. |
| cd dart && dartanalyzer bin/*.dart lib/*.dart test/*.dart | grep -v '\.mojom\.dart' |
| |
| # Installs dart dependencies. |
| dart/packages: dart/pubspec.yaml |
| cd dart && pub get |
| |
| # TODO(nlacasse): Remove this task and dart/bin/syncbase.dart when the tests |
| # are stable enough to reliably test syncbase. |
| .PHONY: run-syncbase-app |
| run-syncbase-app: gen/mojo/syncbase_server.mojo dart/packages dart/lib/gen/dart-pkg/mojom/lib/mojo/syncbase.mojom.dart |
| V23_MOJO_FLAGS=$(V23_MOJO_FLAGS) $(MOJO_DIR)/src/mojo/devtools/common/mojo_run $(MOJO_SHELL_FLAGS) $(MOJO_ANDROID_FLAGS) $(PWD)/dart/bin/syncbase.dart |
| |
| .PHONY: test |
| test: dart/packages gen/mojo/echo_server.mojo gen/mojo/syncbase_server.mojo gen-mojom |
| V23_MOJO_FLAGS=$(V23_MOJO_FLAGS) $(MOJO_DIR)/src/mojo/devtools/common/mojo_test $(MOJO_SHELL_FLAGS) $(MOJO_ANDROID_FLAGS) --shell-path $(MOJO_DIR)/src/out/Debug/mojo_shell tests |
| |
| .PHONY: clean |
| clean: |
| rm -rf gen |
| rm -rf dart/{lib/gen,packages,.packages,pubspec.lock} |