mirror of
https://github.com/netdata/netdata.git
synced 2025-04-06 22:38:55 +00:00
Handle GOROOT inside build system instead of outside. (#18296)
* Handle GOROOT inside build system instead of outside. * Fix parsing of GOROOT value.
This commit is contained in:
parent
f9a773ea7e
commit
bfd83397dc
3 changed files with 19 additions and 7 deletions
4
.github/workflows/build.yml
vendored
4
.github/workflows/build.yml
vendored
|
@ -1071,10 +1071,6 @@ jobs:
|
|||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: "^1.22"
|
||||
- name: Set GOROOT
|
||||
id: goroot
|
||||
if: needs.file-check.outputs.run == 'true'
|
||||
run: Add-Content -Path "$env:GITHUB_ENV" -Value "GOROOT=$(go.exe env GOROOT)"
|
||||
- name: Set Up Dependencies
|
||||
id: deps
|
||||
if: needs.file-check.outputs.run == 'true'
|
||||
|
|
|
@ -21,11 +21,12 @@ endif()
|
|||
# and fall back to looking in PATH. For the specific case of MSYS2, we prefer a Windows install over an MSYS2 install.
|
||||
if(DEFINED $ENV{GOROOT})
|
||||
find_program(GO_EXECUTABLE go PATHS "$ENV{GOROOT}/bin" DOC "Go toolchain" NO_DEFAULT_PATH)
|
||||
set(GO_ROOT $ENV{GOROOT})
|
||||
elseif(OS_WINDOWS)
|
||||
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
|
||||
find_program(GO_EXECUTABLE go PATHS C:/go/bin "C:/Program Files/go/bin" DOC "Go toolchain" NO_DEFAULT_PATH)
|
||||
else()
|
||||
find_program(GO_EXECUTABLE go PATHS /c/go/bin "/c/Program Files/go/bin" /mingw64/bin /ucrt64/bin /clang64/bin DOC "Go toolchain" NO_DEFAULT_PATH)
|
||||
find_program(GO_EXECUTABLE go PATHS /c/go/bin "/c/Program Files/go/bin" /mingw64/lib/go/bin /ucrt64/lib/go/bin /clang64/lib/go/bin DOC "Go toolchain" NO_DEFAULT_PATH)
|
||||
endif()
|
||||
else()
|
||||
find_program(GO_EXECUTABLE go PATHS /usr/local/go/bin DOC "Go toolchain" NO_DEFAULT_PATH)
|
||||
|
@ -41,12 +42,27 @@ if (GO_EXECUTABLE)
|
|||
if (RESULT EQUAL 0)
|
||||
string(REGEX MATCH "go([0-9]+\\.[0-9]+(\\.[0-9]+)?)" GO_VERSION_STRING "${GO_VERSION_STRING}")
|
||||
string(REGEX MATCH "([0-9]+\\.[0-9]+(\\.[0-9]+)?)" GO_VERSION_STRING "${GO_VERSION_STRING}")
|
||||
else()
|
||||
unset(GO_VERSION_STRING)
|
||||
endif()
|
||||
|
||||
if(NOT DEFINED GO_ROOT)
|
||||
execute_process(
|
||||
COMMAND ${GO_EXECUTABLE} env GOROOT
|
||||
OUTPUT_VARIABLE GO_ROOT
|
||||
RESULT_VARIABLE RESULT
|
||||
)
|
||||
if(RESULT EQUAL 0)
|
||||
string(REGEX REPLACE "\n$" "" GO_ROOT "${GO_ROOT}")
|
||||
else()
|
||||
unset(GO_ROOT)
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(
|
||||
Go
|
||||
REQUIRED_VARS GO_EXECUTABLE
|
||||
REQUIRED_VARS GO_EXECUTABLE GO_ROOT
|
||||
VERSION_VAR GO_VERSION_STRING
|
||||
)
|
||||
|
|
|
@ -33,7 +33,7 @@ macro(add_go_target target output build_src build_dir)
|
|||
|
||||
add_custom_command(
|
||||
OUTPUT ${output}
|
||||
COMMAND "${CMAKE_COMMAND}" -E env CGO_ENABLED=0 GOPROXY=https://proxy.golang.org,direct "${GO_EXECUTABLE}" build -buildvcs=false -ldflags "${GO_LDFLAGS}" -o "${CMAKE_BINARY_DIR}/${output}" "./${build_dir}"
|
||||
COMMAND "${CMAKE_COMMAND}" -E env GOROOT=${GO_ROOT} CGO_ENABLED=0 GOPROXY=https://proxy.golang.org,direct "${GO_EXECUTABLE}" build -buildvcs=false -ldflags "${GO_LDFLAGS}" -o "${CMAKE_BINARY_DIR}/${output}" "./${build_dir}"
|
||||
DEPENDS ${${target}_DEPS}
|
||||
COMMENT "Building Go component ${output}"
|
||||
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/${build_src}"
|
||||
|
|
Loading…
Add table
Reference in a new issue