pingcap / tidb

TiDB is an open-source, cloud-native, distributed, MySQL-Compatible database for elastic scale and real-time analytics. Try AI-powered Chat2Query free at : https://www.pingcap.com/tidb-serverless/
https://pingcap.com
Apache License 2.0
37.09k stars 5.83k forks source link

can't build master branch on Mac M1 #26573

Closed feiquan123 closed 3 years ago

feiquan123 commented 3 years ago

Bug Report

can't build master branch on MAC M1

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

follow Quick start:

mkdir -p $GOPATH/src/github.com/pingcap
cd $GOPATH/src/github.com/pingcap
git clone https://github.com/pingcap/tidb.git
cd tidb
make

2. What did you expect to see? (Required)

success build master branch on Mac M1

3. What did you see instead (Required)

run make error:

CGO_ENABLED=1 GO111MODULE=on go build  -tags codes  -ldflags '-L/opt/homebrew/opt/llvm/lib -X "github.com/pingcap/parser/mysql.TiDBReleaseVersion=v5.2.0-alpha-391-g7726e5519-dirty" -X "github.com/pingcap/tidb/util/versioninfo.TiDBBuildTS=2021-07-26 09:37:51" -X "github.com/pingcap/tidb/util/versioninfo.TiDBGitHash=7726e55191a84cfa1c0b0440ec994065659f8ae2" -X "github.com/pingcap/tidb/util/versioninfo.TiDBGitBranch=master" -X "github.com/pingcap/tidb/util/versioninfo.TiDBEdition=Community" ' -o bin/tidb-server tidb-server/main.go
# github.com/shirou/gopsutil/cpu
../../../../pkg/mod/github.com/shirou/gopsutil@v3.21.2+incompatible/cpu/cpu_darwin_cgo.go:13:5: error: 'TARGET_OS_MAC' is not defined, evaluates to 0 [-Werror,-Wundef-prefix=TARGET_OS_]
#if TARGET_OS_MAC
    ^
1 error generated.

4. What is your TiDB version? (Required)

master

go env:

GOARCH="amd64"
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOVERSION="go1.16.3"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/kw/0nynw5h548ndftn_1k29bvh80000gn/T/go-build2426549902=/tmp/go-build -gno-record-gcc-switches -fno-common"
feiquan123 commented 3 years ago

need run go get -u github.com/shirou/gopsutil to update github.com/shirou/gopsutil version

go: downloading github.com/shirou/gopsutil v3.21.6+incompatible
go get: upgraded github.com/shirou/gopsutil v3.21.2+incompatible => v3.21.6+incompatible
feiquan123 commented 3 years ago

error again when run make

CGO_ENABLED=1 GO111MODULE=on go build  -tags codes  -ldflags '-L/opt/homebrew/opt/llvm/lib -X "github.com/pingcap/parser/mysql.TiDBReleaseVersion=v5.2.0-alpha-391-g7726e5519-dirty" -X "github.com/pingcap/tidb/util/versioninfo.TiDBBuildTS=2021-07-26 09:38:12" -X "github.com/pingcap/tidb/util/versioninfo.TiDBGitHash=7726e55191a84cfa1c0b0440ec994065659f8ae2" -X "github.com/pingcap/tidb/util/versioninfo.TiDBGitBranch=master" -X "github.com/pingcap/tidb/util/versioninfo.TiDBEdition=Community" ' -o bin/tidb-server tidb-server/main.go
# command-line-arguments
flag provided but not defined: -L/opt/homebrew/opt/llvm/lib
usage: link [options] main.o
  -B note
        add an ELF NT_GNU_BUILD_ID note when using ELF
  -E entry
        set entry symbol name
  -H type
        set header type
  -I linker
        use linker as ELF dynamic linker
...
feiquan123 commented 3 years ago

i ran brew install llvm

==> Summary
🍺  /opt/homebrew/Cellar/llvm/12.0.1: 9,791 files, 1.5GB
feiquan123 commented 3 years ago

my $LDFLAGS same with -ldflags '-L/opt/homebrew/opt/llvm/lib ...'

echo $LDFLAGS
-L/opt/homebrew/opt/llvm/lib
feiquan123 commented 3 years ago

success install 🤓 set LDFLAGS is empyt run LDFLAGS= make

sticnarf commented 3 years ago

Yep, gopsutil does not compile with the llvm installed by homebrew.

Close it as the problem is resolved.

ti-srebot commented 3 years ago

Not a bug