Skip to content

Commit

Permalink
feat: extract Go build to location according to package name
Browse files Browse the repository at this point in the history
  • Loading branch information
threeal committed Apr 23, 2024
1 parent 3a49a31 commit 4475cf0
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions cmake/SetupGo.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,23 @@ function(setup_go)
set(PACKAGE_EXT .tar.gz)
endif()

set(GO_PACKAGE go${VERSION}.${OS}-${ARCH}${PACKAGE_EXT})
set(GO_EXECUTABLE ${CMAKE_BINARY_DIR}/_deps/go/bin/go${EXECUTABLE_EXT})
set(GO_BUILD go${VERSION}.${OS}-${ARCH})
set(GO_PACKAGE ${GO_BUILD}${PACKAGE_EXT})
set(GO_EXECUTABLE ${CMAKE_BINARY_DIR}/_deps/${GO_BUILD}/go/bin/go${EXECUTABLE_EXT})

if(NOT EXISTS ${GO_EXECUTABLE})
# Download the Go build.
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/_deps)
file(DOWNLOAD https://go.dev/dl/${GO_PACKAGE} ${CMAKE_BINARY_DIR}/_deps/${GO_PACKAGE})

# Extract the Go build.
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/_deps/${GO_BUILD})
execute_process(
COMMAND tar -xf ${CMAKE_BINARY_DIR}/_deps/${GO_PACKAGE} -C ${CMAKE_BINARY_DIR}/_deps
COMMAND tar -xf ${CMAKE_BINARY_DIR}/_deps/${GO_PACKAGE} -C ${CMAKE_BINARY_DIR}/_deps/${GO_BUILD}
RESULT_VARIABLE RES
)
if(NOT RES EQUAL 0)
message(FATAL_ERROR "Failed to extract '${CMAKE_BINARY_DIR}/_deps/${GO_PACKAGE}' to '${CMAKE_BINARY_DIR}/_deps' (${RES})")
message(FATAL_ERROR "Failed to extract '${CMAKE_BINARY_DIR}/_deps/${GO_PACKAGE}' to '${CMAKE_BINARY_DIR}/_deps/${GO_BUILD}' (${RES})")
endif()

# Remove the downloaded Go build to free up space.
Expand Down

0 comments on commit 4475cf0

Please # to comment.