Skip to content

Commit

Permalink
move go module to be available for all go bindings
Browse files Browse the repository at this point in the history
Signed-off-by: vsoch <vsoch@users.noreply.github.com>
  • Loading branch information
vsoch committed Sep 12, 2023
1 parent ba4bdbf commit c180a46
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 27 deletions.
27 changes: 6 additions & 21 deletions cmake/GolangSimple.cmake
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@

set(CUSTOM_GO_PATH "${CMAKE_SOURCE_DIR}/resource/reapi/bindings/go")
set(GOPATH "${CMAKE_CURRENT_BINARY_DIR}/go")
set(TEST_FLAGS "-L${CMAKE_SOURCE_DIR}/resource/reapi/bindings/c/.libs -lreapi_cli -L${CMAKE_SOURCE_DIR}/resource/.libs -lresource -lflux-idset -lstdc++ -lczmq -ljansson -lhwloc -lboost_system -lflux-hostlist -lboost_graph -lyaml-cpp")

# Convert GOPATH list, if set, to proper GOPATH environment variable.
# Otherwise we'll inherit the caller's GOPATH environment.
#IF (GOPATH)
# SET (_gopath "${GOPATH}")
# IF (NOT WIN32)
# STRING (REPLACE ";" ":" _gopath "${_gopath}")
# ENDIF (NOT WIN32)
# SET (ENV{GOPATH} "${_gopath}")
#ENDIF (GOPATH)

# This probably isn't necessary, although if we could build fluxcli into it maybe
file(MAKE_DIRECTORY ${GOPATH})
Expand All @@ -22,10 +11,6 @@ function(GO_GET TARG)
endfunction(GO_GET)

# ADD_GO_INSTALLABLE_PROGRAM builds a custom go program (primarily for testing)
# TODO only got this working by sudo cp -R fluxcli/ /usr/local/go/src/
# I don't understand why we have "fluxcli" akin to a module in GOROOT
# when it should be github.com/.../etc/fluxcli
# Should we be adding like, YAML_CPPLIBS as an extra dependency?
function(ADD_GO_INSTALLABLE_PROGRAM NAME MAIN_SRC CGO_CFLAGS CGO_LIBRARY_FLAGS)
message(STATUS "GOPATH: ${GOPATH}")
message(STATUS "CGO_LDFLAGS (before): ${CGO_LIBRARY_FLAGS}")
Expand All @@ -38,20 +23,20 @@ function(ADD_GO_INSTALLABLE_PROGRAM NAME MAIN_SRC CGO_CFLAGS CGO_LIBRARY_FLAGS)

# set(ENV{<variable>} [<value>]) as environment OR without CMake variable
# Note that I couldn't get this to work (the spaces are always escaped) so I hard coded for now
# We need a solution taht takes the CGO_LIBRARY_FLAGS arg, and can pass (with spaces not escaped) to add_custom_command
# We need a solution that takes the CGO_LIBRARY_FLAGS arg, and can pass (with spaces not escaped) to add_custom_command
SET ($ENV{CGO_LDFLAGS} "${CGO_LDFLAGS}")
message(STATUS "CGO_LDFLAGS (after): ${CGO_LDFLAGS}")
SET ($CMAKE_GO_FLAGS "${CGO_LDFLAGS}")
# SET (CMAKE_GO_FLAGS "${CGO_LDFLAGS}")
add_custom_command(TARGET ${NAME}
COMMAND GOPATH=${GOPATH}:${CUSTOM_GO_PATH} GOOS=linux G0111MODULE=off CGO_CFLAGS="${CGO_CFLAGS}" CGO_LDFLAGS='-L${CMAKE_SOURCE_DIR}/resource/reapi/bindings/c/.libs -lreapi_cli -L${CMAKE_SOURCE_DIR}/resource/.libs -lresource -lflux-idset -lstdc++ -lczmq -ljansson -lhwloc -lboost_system -lflux-hostlist -lboost_graph -lyaml-cpp' go build -ldflags '-w'
COMMAND GOPATH=${GOPATH}:${CUSTOM_GO_PATH} GOOS=linux G0111MODULE=off CGO_CFLAGS="${CGO_CFLAGS}" CGO_LDFLAGS='-L${CMAKE_BINARY_DIR}/resource/reapi/bindings -lreapi_cli -L${CMAKE_BINARY_DIR}/resource -lresource -lflux-idset -lstdc++ -lczmq -ljansson -lhwloc -lboost_system -lflux-hostlist -lboost_graph -lyaml-cpp' go build -ldflags '-w'
-o "${CMAKE_CURRENT_SOURCE_DIR}/${NAME}"
${CMAKE_GO_FLAGS} ${MAIN_SRC}
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
DEPENDS ${MAIN_SRC_ABS}
COMMENT "Building Go library")
# foreach(DEP ${ARGN})
# add_dependencies(${NAME} ${DEP})
# endforeach()
foreach(DEP ${ARGN})
add_dependencies(${NAME} ${DEP})
endforeach()

add_custom_target(${NAME}_all ALL DEPENDS ${NAME})
install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${NAME} DESTINATION bin)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module github.com/flux-framework/flux-sched/resource/reapi/bindings/go/src/fluxcli
module github.com/flux-framework/flux-sched/resource/reapi/bindings/go

go 1.19
go 1.19
6 changes: 3 additions & 3 deletions resource/reapi/bindings/go/src/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
set(TARGET main)
set(SRCS main.go)
set(CGO_CFLAGS "-I${CMAKE_SOURCE_DIR}/resource/reapi/bindings/c")
set(CGO_LIBRARY_FLAGS "-L${CMAKE_SOURCE_DIR}/resource/reapi/bindings/c/.libs;-lreapi_cli;-L${CMAKE_SOURCE_DIR}/resource/.libs;-lresource;-lflux-idset;-lstdc++;-lczmq;-ljansson;-lhwloc;-lboost_system;-lflux-hostlist;-lboost_graph;-lyaml-cpp")
set(CGO_CFLAGS "-I${CMAKE_BINARY_DIR}/resource/reapi/bindings/c")
set(CGO_LIBRARY_FLAGS "-L${CMAKE_BINARY_DIR}/resource/reapi/bindings;-lreapi_cli;-L${CMAKE_BINARY_DIR}/resource;-lresource;-lflux-idset;-lstdc++;-lczmq;-ljansson;-lhwloc;-lboost_system;-lflux-hostlist;-lboost_graph;-lyaml-cpp")

# GO_GET(go_redis github.com/hoisie/redis)
# main main.go
ADD_GO_INSTALLABLE_PROGRAM(${TARGET} ${SRCS} "${CGO_CFLAGS}" "${CGO_LIBRARY_FLAGS}")
ADD_GO_INSTALLABLE_PROGRAM(${TARGET} ${SRCS} "${CGO_CFLAGS}" "${CGO_LIBRARY_FLAGS}" reapi_module reapi_cli flux::core)
3 changes: 2 additions & 1 deletion resource/reapi/bindings/go/src/test/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ package main

import (
"flag"
"fluxcli"
"fmt"
"os"

"github.com/flux-framework/flux-sched/resource/reapi/bindings/go/src/fluxcli"
)

func main() {
Expand Down

0 comments on commit c180a46

Please sign in to comment.