From 549e3c9eb31b93eadeb60e43d457c3f2d0cf690c Mon Sep 17 00:00:00 2001 From: Yiqun Zhang Date: Tue, 10 Dec 2019 22:45:25 -0500 Subject: [PATCH 1/3] build: using libflux in OSS --- .circleci/config.yml | 20 +++++++++++++++++++- .gitignore | 1 + Makefile | 37 +++++++++++++++++++++++-------------- 3 files changed, 43 insertions(+), 15 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index f44616f79f..28b4f98a65 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,4 +1,19 @@ -version: 2 +version: '2.1' + +commands: + install_rust_compiler: + description: > + This will install the rust compiler with the rust tools. + steps: + - run: + name: Install clang + command: sudo apt-get install -y --no-install-recommends clang + - run: + name: Install rust compiler + command: | + curl https://sh.rustup.rs -sSf | \ + sh -s -- --default-toolchain stable -y + echo 'source $HOME/.cargo/env' >> $BASH_ENV jobs: litmus_daily: @@ -65,6 +80,7 @@ jobs: - influxdb-gomod-{{ checksum "go.sum" }} # Just match the go.sum checksum cache. - run: sudo apt-get install -y netcat-openbsd - run: sudo apt-get install -y bzr + - install_rust_compiler - run: make protoc - run: make build - run: @@ -154,6 +170,7 @@ jobs: keys: - influxdb-gomod-{{ checksum "go.sum" }} # Matches based on go.sum checksum. - run: sudo apt-get install -y bzr + - install_rust_compiler - run: mkdir -p $TEST_RESULTS - run: make test-go # This uses the test cache so it may succeed or fail quickly. - run: make vet @@ -193,6 +210,7 @@ jobs: steps: - checkout - run: sudo apt-get install -y bzr + - install_rust_compiler - run: make checkcommit # Speed up `make build` by restoring caches from previous runs. diff --git a/.gitignore b/.gitignore index f4ab4023f1..d517c954fb 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ vendor .tern-project .DS_Store .idea +.cgo_ldflags # binary databases influxd.bolt diff --git a/Makefile b/Makefile index e419deaddd..d748d10675 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ # Top level Makefile for the entire project # -# This Makefile encodes the "go generate" prerequeisites ensuring that the proper tooling is installed and -# that the generate steps are executed when their prerequeisites files change. +# This Makefile encodes the "go generate" prerequisites ensuring that the proper tooling is installed and +# that the generate steps are executed when their prerequisite files change. # # This Makefile follows a few conventions: # @@ -12,18 +12,20 @@ # # SUBDIRS are directories that have their own Makefile. -# It is required that all subdirs have the `all` and `clean` targets. +# It is required that all SUBDIRS have the `all` and `clean` targets. SUBDIRS := http ui chronograf query storage +# The 'libflux' tag is required for instructing the flux to be compiled with the Rust parser +GO_TAGS=libflux GO_ARGS=-tags '$(GO_TAGS)' # Test vars can be used by all recursive Makefiles export GOOS=$(shell go env GOOS) -export GO_BUILD=env GO111MODULE=on go build $(GO_ARGS) -export GO_INSTALL=env GO111MODULE=on go install $(GO_ARGS) -export GO_TEST=env GOTRACEBACK=all GO111MODULE=on go test $(GO_ARGS) +export GO_BUILD=env GO111MODULE=on CGO_LDFLAGS="$$(cat .cgo_ldflags)" go build $(GO_ARGS) +export GO_INSTALL=env GO111MODULE=on CGO_LDFLAGS="$$(cat .cgo_ldflags)" go install $(GO_ARGS) +export GO_TEST=env FLUX_PARSER_TYPE=rust GOTRACEBACK=all GO111MODULE=on CGO_LDFLAGS="$$(cat .cgo_ldflags)" go test $(GO_ARGS) # Do not add GO111MODULE=on to the call to go generate so it doesn't pollute the environment. export GO_GENERATE=go generate $(GO_ARGS) -export GO_VET=env GO111MODULE=on go vet $(GO_ARGS) +export GO_VET=env GO111MODULE=on CGO_LDFLAGS="$$(cat .cgo_ldflags)" go vet $(GO_ARGS) export GO_RUN=env GO111MODULE=on go run $(GO_ARGS) export PATH := $(PWD)/bin/$(GOOS):$(PATH) @@ -50,7 +52,7 @@ CMDS := \ # This target sets up the dependencies to correctly build all go commands. # Other targets must depend on this target to correctly builds CMDS. ifeq ($(GOARCH), arm64) - all: GO_ARGS=-tags ' assets noasm $(GO_TAGS)' + all: GO_ARGS=-tags 'assets noasm $(GO_TAGS)' else all: GO_ARGS=-tags 'assets $(GO_TAGS)' endif @@ -64,7 +66,7 @@ subdirs: $(SUBDIRS) # # Define targets for commands # -$(CMDS): $(SOURCES) +$(CMDS): $(SOURCES) libflux $(GO_BUILD) -o $@ ./cmd/$(shell basename "$@") # Ease of use build for just the go binary @@ -96,6 +98,12 @@ ui_client: # Define action only targets # +libflux: .cgo_ldflags + +.cgo_ldflags: go.mod + $(GO_RUN) github.com/influxdata/flux/internal/cmd/flux-config --libs --verbose > .cgo_ldflags.tmp + mv .cgo_ldflags.tmp .cgo_ldflags + fmt: $(SOURCES_NO_VENDOR) gofmt -w -s $^ @@ -120,7 +128,7 @@ generate: subdirs test-js: node_modules make -C ui test -test-go: +test-go: libflux $(GO_TEST) ./... test-promql-e2e: @@ -132,13 +140,13 @@ test-integration: test: test-go test-js -test-go-race: +test-go-race: libflux $(GO_TEST) -v -race -count=1 ./... -vet: +vet: libflux $(GO_VET) -v ./... -bench: +bench: libflux $(GO_TEST) -bench=. -run=^$$ ./... build: all @@ -158,6 +166,7 @@ clean: @for d in $(SUBDIRS); do $(MAKE) -C $$d clean; done $(RM) -r bin $(RM) -r dist + $(RM) .cgo_ldflags define CHRONOGIRAFFE ._ o o @@ -186,4 +195,4 @@ protoc: chmod +x /go/bin/protoc # .PHONY targets represent actions that do not create an actual file. -.PHONY: all subdirs $(SUBDIRS) run fmt checkfmt tidy checktidy checkgenerate test test-go test-js test-go-race bench clean node_modules vet nightly chronogiraffe dist ping protoc e2e run-e2e influxd +.PHONY: all subdirs $(SUBDIRS) run fmt checkfmt tidy checktidy checkgenerate test test-go test-js test-go-race bench clean node_modules vet nightly chronogiraffe dist ping protoc e2e run-e2e influxd libflux From 4ea8d01a235d040783604a37192193001ed349d0 Mon Sep 17 00:00:00 2001 From: Yiqun Zhang Date: Fri, 13 Dec 2019 10:58:00 -0500 Subject: [PATCH 2/3] fix: test baseline to use rust parser! --- .circleci/config.yml | 2 +- http/query_handler_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 28b4f98a65..5d9fb5b0c9 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -179,7 +179,7 @@ jobs: - run: GO111MODULE=on go mod vendor # staticcheck looks in vendor for dependencies. - run: GO111MODULE=on go install honnef.co/go/tools/cmd/staticcheck # Install staticcheck from the version we specify in go.mod. - run: GO111MODULE=on staticcheck ./... - - run: GOTRACEBACK=all GO111MODULE=on gotestsum --format standard-verbose --junitfile /tmp/test-results/gotestsum.xml -- -race -count=1 ./... + - run: GOTRACEBACK=all GO111MODULE=on FLUX_PARSER_TYPE=rust gotestsum --format standard-verbose --junitfile /tmp/test-results/gotestsum.xml -- -race -count=1 ./... # TODO add these checks to the Makefile # - run: go get -v -t -d ./... diff --git a/http/query_handler_test.go b/http/query_handler_test.go index 66cbbd949d..a4df1ccb04 100644 --- a/http/query_handler_test.go +++ b/http/query_handler_test.go @@ -245,7 +245,7 @@ func TestFluxHandler_postFluxAST(t *testing.T) { name: "get ast from()", w: httptest.NewRecorder(), r: httptest.NewRequest("POST", "/api/v2/query/ast", bytes.NewBufferString(`{"query": "from()"}`)), - want: `{"ast":{"type":"Package","package":"main","files":[{"type":"File","location":{"start":{"line":1,"column":1},"end":{"line":1,"column":7},"source":"from()"},"metadata":"parser-type=go","package":null,"imports":null,"body":[{"type":"ExpressionStatement","location":{"start":{"line":1,"column":1},"end":{"line":1,"column":7},"source":"from()"},"expression":{"type":"CallExpression","location":{"start":{"line":1,"column":1},"end":{"line":1,"column":7},"source":"from()"},"callee":{"type":"Identifier","location":{"start":{"line":1,"column":1},"end":{"line":1,"column":5},"source":"from"},"name":"from"}}}]}]}} + want: `{"ast":{"type":"Package","package":"main","files":[{"type":"File","location":{"start":{"line":1,"column":1},"end":{"line":1,"column":7},"source":"from()"},"metadata":"parser-type=rust","package":null,"imports":null,"body":[{"type":"ExpressionStatement","location":{"start":{"line":1,"column":1},"end":{"line":1,"column":7},"source":"from()"},"expression":{"type":"CallExpression","location":{"start":{"line":1,"column":1},"end":{"line":1,"column":7},"source":"from()"},"callee":{"type":"Identifier","location":{"start":{"line":1,"column":1},"end":{"line":1,"column":5},"source":"from"},"name":"from"}}}]}]}} `, status: http.StatusOK, }, From 1c327904c9e4e391be3f141f542d16f402142d96 Mon Sep 17 00:00:00 2001 From: Yiqun Zhang Date: Mon, 16 Dec 2019 10:13:40 -0500 Subject: [PATCH 3/3] fix: run gotest with libflux tag and cgo ldflags --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 5d9fb5b0c9..dbe054b9e5 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -179,7 +179,7 @@ jobs: - run: GO111MODULE=on go mod vendor # staticcheck looks in vendor for dependencies. - run: GO111MODULE=on go install honnef.co/go/tools/cmd/staticcheck # Install staticcheck from the version we specify in go.mod. - run: GO111MODULE=on staticcheck ./... - - run: GOTRACEBACK=all GO111MODULE=on FLUX_PARSER_TYPE=rust gotestsum --format standard-verbose --junitfile /tmp/test-results/gotestsum.xml -- -race -count=1 ./... + - run: GOTRACEBACK=all GO111MODULE=on FLUX_PARSER_TYPE=rust CGO_LDFLAGS="$(cat .cgo_ldflags)" gotestsum --format standard-verbose --junitfile /tmp/test-results/gotestsum.xml -- -race -count=1 -tags 'libflux' ./... # TODO add these checks to the Makefile # - run: go get -v -t -d ./...