Handle GOROOT inside build system instead of outside. (#18296)
* Handle GOROOT inside build system instead of outside. * Fix parsing of GOROOT value.
Austin S. Hemmelgarn committed
Aug 12, 2024 at 11:55 UTC
bfd83397dcc6bd99e7e19b9e68ec86cdc021ca4f
3 files changed
+19
-7
.github/workflows/build.yml
-4
@@ -1071,10 +1071,6 @@ jobs:
1071
uses: actions/setup-go@v5
1072
with:
1073
go-version: "^1.22"
1074
- - name: Set GOROOT
1075
- id: goroot
1076
- if: needs.file-check.outputs.run == 'true'
1077
- run: Add-Content -Path "$env:GITHUB_ENV" -Value "GOROOT=$(go.exe env GOROOT)"
1074
- name: Set Up Dependencies
1075
id: deps
1076
if: needs.file-check.outputs.run == 'true'
packaging/cmake/Modules/FindGo.cmake
+18
-2
@@ -21,11 +21,12 @@ endif()
21
# and fall back to looking in PATH. For the specific case of MSYS2, we prefer a Windows install over an MSYS2 install.
22
if(DEFINED $ENV{GOROOT})
23
find_program(GO_EXECUTABLE go PATHS "$ENV{GOROOT}/bin" DOC "Go toolchain" NO_DEFAULT_PATH)
24
+ set(GO_ROOT $ENV{GOROOT})
25
elseif(OS_WINDOWS)
26
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
27
find_program(GO_EXECUTABLE go PATHS C:/go/bin "C:/Program Files/go/bin" DOC "Go toolchain" NO_DEFAULT_PATH)
28
else()
28
- 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)
29
+ 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)
30
endif()
31
else()
32
find_program(GO_EXECUTABLE go PATHS /usr/local/go/bin DOC "Go toolchain" NO_DEFAULT_PATH)
@@ -41,12 +42,27 @@ if (GO_EXECUTABLE)
42
if (RESULT EQUAL 0)
43
string(REGEX MATCH "go([0-9]+\\.[0-9]+(\\.[0-9]+)?)" GO_VERSION_STRING "${GO_VERSION_STRING}")
44
string(REGEX MATCH "([0-9]+\\.[0-9]+(\\.[0-9]+)?)" GO_VERSION_STRING "${GO_VERSION_STRING}")
45
+ else()
46
+ unset(GO_VERSION_STRING)
47
+ endif()
48
+
49
+ if(NOT DEFINED GO_ROOT)
50
+ execute_process(
51
+ COMMAND ${GO_EXECUTABLE} env GOROOT
52
+ OUTPUT_VARIABLE GO_ROOT
53
+ RESULT_VARIABLE RESULT
54
+ )
55
+ if(RESULT EQUAL 0)
56
+ string(REGEX REPLACE "\n$" "" GO_ROOT "${GO_ROOT}")
57
+ else()
58
+ unset(GO_ROOT)
59
+ endif()
60
endif()
61
endif()
62
63
include(FindPackageHandleStandardArgs)
64
find_package_handle_standard_args(
65
Go
50
- REQUIRED_VARS GO_EXECUTABLE
66
+ REQUIRED_VARS GO_EXECUTABLE GO_ROOT
67
VERSION_VAR GO_VERSION_STRING
68
)
packaging/cmake/Modules/NetdataGoTools.cmake
+1
-1
@@ -33,7 +33,7 @@ macro(add_go_target target output build_src build_dir)
33
34
add_custom_command(
35
OUTPUT ${output}
36
- 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}"
36
+ 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}"
37
DEPENDS ${${target}_DEPS}
38
COMMENT "Building Go component ${output}"
39
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/${build_src}"