Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trying to find a clean way to integrate new changes here... might have to start over #1

Open
wants to merge 18 commits into
base: test-updates-to-golang-with-rebase
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ RUN sudo apt-get -qq install -y --no-install-recommends \
curl

# Assuming installing to /usr/local
ENV LD_LIBRARY_PATH=/usr/local/lib
ENV LD_LIBRARY_PATH=/usr/lib:/usr/local/lib

RUN curl -s -L https://github.com/Kitware/CMake/releases/download/v3.26.4/cmake-3.26.4-linux-$(uname -m).sh > cmake.sh ;\
sudo bash cmake.sh --prefix=/usr/local --skip-license ;\
Expand Down
5 changes: 4 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
"vscode": {
"settings": {
"terminal.integrated.defaultProfile.linux": "bash"
}
},
"extensions": [
"ms-vscode.cmake-tools"
]
}
}
},
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,6 @@ compile_flags.txt
# Rules to ignore auto-generated test harness scripts
test_*.t
!/src/bindings/python/test_commands/test_runner.t

# Go
resource/reapi/bindings/go/src/test/main
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,12 @@ if(ENABLE_COVERAGE)
SET( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${COVERAGE_FLAGS}" )
endif()

# export WITH_GO=yes
if(DEFINED ENV{WITH_GO})
message(STATUS "WITH_GO detected in main CMakeLists.txt to build go bindings")
include(GolangSimple)
endif()

include_directories(.)
add_subdirectory( etc )
add_subdirectory( src )
Expand Down
26 changes: 25 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,37 @@ be set to the same prefix as was used to install the target flux-core.

For example, if flux-core was installed in `$FLUX_CORE_PREFIX`:

```
```bash
./configure --prefix=${FLUX_CORE_PREFIX}
make
make check
make install
```

To build go bindings, you will need go (tested with 1.19.10) available, and then:

```bash
export WITH_GO=yes
./configure
make
```

To run just one test, you can cd into t

```bash
$ ./t9001-golang-basic.t
ok 1 - match allocate 1 slot: 1 socket: 1 core (pol=default)
ok 2 - match allocate 2 slots: 2 sockets: 5 cores 1 gpu 6 memory
# passed all 2 test(s)
1..2
```

To run full tests (more robust and mimics what happens in CI) you can do:

```bash
make check
```

##### Flux Instance

The examples below walk through exercising functioning flux-sched modules (i.e.,
Expand Down
44 changes: 44 additions & 0 deletions cmake/GolangSimple.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@

set(CUSTOM_GO_PATH "${CMAKE_SOURCE_DIR}/resource/reapi/bindings/go")
set(GOPATH "${CMAKE_CURRENT_BINARY_DIR}/go")

# This probably isn't necessary, although if we could build fluxcli into it maybe
file(MAKE_DIRECTORY ${GOPATH})

# GO_GET will retrieve a go module that needs to be installed
function(GO_GET TARG)
add_custom_target(${TARG} env GOPATH=${GOPATH} go get ${ARGN})
endfunction(GO_GET)

# ADD_GO_INSTALLABLE_PROGRAM builds a custom go program (primarily for testing)
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}")
message(STATUS "TEST_FLAGS: ${TEST_FLAGS}")
get_filename_component(MAIN_SRC_ABS ${MAIN_SRC} ABSOLUTE)
add_custom_target(${NAME})

# string(REPLACE <match-string> <replace-string> <out-var> <input>...)
STRING(REPLACE ";" " " CGO_LDFLAGS "${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 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}")

add_custom_command(TARGET ${NAME}
COMMAND GOPATH=${GOPATH}:${CUSTOM_GO_PATH} GOOS=linux G0111MODULE=off CGO_CFLAGS="${CGO_CFLAGS}" CGO_LDFLAGS='-L${CMAKE_BINARY_DIR}/resource/reapi/bindings -L/workspaces/fs-dev/resource/libjobspec -ljobspec_conv -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()

add_custom_target(${NAME}_all ALL DEPENDS ${NAME})
install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${NAME} DESTINATION bin)
endfunction(ADD_GO_INSTALLABLE_PROGRAM)
12 changes: 12 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ AC_PROG_LN_S
AC_PROG_MAKE_SET
AM_PROG_CC_C_O
AX_CODE_COVERAGE
# Check to build with Go
AC_PROG_GO([go])
AC_PATH_PROG(GO, go, nogo)
AS_IF([test "$ac_cv_path_GO" = "nogo"],AC_MSG_NOTICE([could not find go]),[])
AM_CONDITIONAL([WITH_GO], [test "X$WITH_GO" != "X"])
if test "$WITH_GO" = yes; then
GO_PRINTOUT=$( echo "GO...............: $(go version | sed 's/go version //')" )
fi

if test "$GCC" = yes; then
WARNING_CFLAGS="-Wall -Werror -Werror=missing-field-initializers -Wno-error=deprecated-declarations"
Expand Down Expand Up @@ -202,6 +210,9 @@ AC_CONFIG_FILES([Makefile
resource/reapi/Makefile
resource/reapi/bindings/Makefile
resource/reapi/bindings/c/Makefile
resource/reapi/bindings/go/Makefile
resource/reapi/bindings/go/src/Makefile
resource/reapi/bindings/go/src/test/Makefile
resource/policies/Makefile
resource/policies/base/Makefile
resource/policies/base/test/Makefile
Expand Down Expand Up @@ -231,4 +242,5 @@ echo "
LDFLAGS..........: $LDFLAGS
LIBS.............: $LIBS
Linker...........: $LD
$GO_PRINTOUT
"
5 changes: 5 additions & 0 deletions resource/reapi/bindings/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,8 @@ add_library ( reapi_module STATIC
target_link_libraries(reapi_module PRIVATE
flux::core
)

if(DEFINED ENV{WITH_GO})
message(STATUS "WITH_GO is set to build go bindings")
add_subdirectory( go )
endif()
2 changes: 1 addition & 1 deletion resource/reapi/bindings/Makefile.am
Original file line number Diff line number Diff line change
@@ -1 +1 @@
SUBDIRS = c
SUBDIRS = c go
2 changes: 1 addition & 1 deletion resource/reapi/bindings/c/reapi_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ extern "C" reapi_module_ctx_t *reapi_module_new ()
errno = ENOMEM;
goto out;
}
ctx->h = NULL;
ctx->h = flux_open (NULL, 0);
out:
return ctx;
}
Expand Down
1 change: 1 addition & 0 deletions resource/reapi/bindings/go/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_subdirectory( src )
1 change: 1 addition & 0 deletions resource/reapi/bindings/go/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SUBDIRS = src
3 changes: 3 additions & 0 deletions resource/reapi/bindings/go/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/flux-framework/flux-sched/resource/reapi/bindings/go

go 1.19
1 change: 1 addition & 0 deletions resource/reapi/bindings/go/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_subdirectory( test )
1 change: 1 addition & 0 deletions resource/reapi/bindings/go/src/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SUBDIRS = test
3 changes: 3 additions & 0 deletions resource/reapi/bindings/go/src/fluxcli/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/flux-framework/flux-sched/resource/reapi/bindings/go/src/fluxcli

go 1.19
Loading