Skip to content

Commit

Permalink
This is an automated cherry-pick of pingcap#9961
Browse files Browse the repository at this point in the history
Signed-off-by: ti-chi-bot <[email protected]>
  • Loading branch information
lidezhu authored and ti-chi-bot committed Nov 22, 2023
1 parent d1bd4ff commit 9f69aaa
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 1 deletion.
25 changes: 24 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,30 @@ ifeq (${CDC_ENABLE_VENDOR}, 1)
GOVENDORFLAG := -mod=vendor
endif

<<<<<<< HEAD
GOBUILD := CGO_ENABLED=0 $(GO) build $(BUILD_FLAG) -trimpath $(GOVENDORFLAG)
=======
# Since TiDB add a new dependency on github.com/cloudfoundry/gosigar,
# We need to add CGO_ENABLED=1 to make it work when build TiCDC in Darwin OS.
# These logic is to check if the OS is Darwin, if so, add CGO_ENABLED=1.
# ref: https://github.com/cloudfoundry/gosigar/issues/58#issuecomment-1150925711
# ref: https://github.com/pingcap/tidb/pull/39526#issuecomment-1407952955
OS := "$(shell go env GOOS)"
ifeq (${OS}, "linux")
CGO := 0
else ifeq (${OS}, "darwin")
CGO := 1
endif

BUILD_FLAG =
GOEXPERIMENT=
ifeq ("${ENABLE_FIPS}", "1")
BUILD_FLAG = -tags boringcrypto
GOEXPERIMENT = GOEXPERIMENT=boringcrypto
CGO = 1
endif
GOBUILD := $(GOEXPERIMENT) CGO_ENABLED=$(CGO) $(GO) build $(BUILD_FLAG) -trimpath $(GOVENDORFLAG)
>>>>>>> 120815e494 (Makefile(ticdc): support build cdc in fips mode (#9961))
GOBUILDNOVENDOR := CGO_ENABLED=0 $(GO) build $(BUILD_FLAG) -trimpath
GOTEST := CGO_ENABLED=1 $(GO) test -p $(P) --race
GOTESTNORACE := CGO_ENABLED=1 $(GO) test -p $(P)
Expand Down Expand Up @@ -136,7 +159,7 @@ build-failpoint: check_failpoint_ctl
$(FAILPOINT_DISABLE)

cdc:
$(GOBUILD) -ldflags '$(LDFLAGS)' -o bin/cdc ./cmd/cdc/main.go
$(GOBUILD) -ldflags '$(LDFLAGS)' -o bin/cdc ./cmd/cdc

kafka_consumer:
$(GOBUILD) -ldflags '$(LDFLAGS)' -o bin/cdc_kafka_consumer ./cmd/kafka-consumer/main.go
Expand Down
27 changes: 27 additions & 0 deletions cmd/cdc/fips.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2020 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build boringcrypto
// +build boringcrypto

package main

import (
_ "crypto/tls/fipsonly"
//
"github.com/pingcap/tiflow/pkg/version"
)

func init() {
version.ReleaseVersion += "-fips"
}
1 change: 1 addition & 0 deletions pkg/version/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func SanitizeVersion(v string) string {
return v
}
v = versionHash.ReplaceAllLiteralString(v, "")
v = strings.TrimSuffix(v, "-fips")
v = strings.TrimSuffix(v, "-dirty")
return strings.TrimPrefix(v, "v")
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/version/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,10 @@ func TestCompareVersion(t *testing.T) {
dirtyVersion := semver.New(SanitizeVersion("v6.3.0-dirty"))
require.Equal(t, 1, dirtyVersion.Compare(*MinTiCDCVersion))
require.Equal(t, 0, dirtyVersion.Compare(*semver.New("6.3.0")))

dirtyVersionWithFIPS := semver.New(SanitizeVersion("v6.3.0-dirty-fips"))
require.Equal(t, 1, dirtyVersionWithFIPS.Compare(*MinTiCDCVersion))
require.Equal(t, 0, dirtyVersionWithFIPS.Compare(*semver.New("6.3.0")))
}

func TestReleaseSemver(t *testing.T) {
Expand Down

0 comments on commit 9f69aaa

Please sign in to comment.