Skip to content

Commit

Permalink
test: dockerfile updates for golang-focal for cmake
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 15, 2023
1 parent ec5626d commit 4d66306
Show file tree
Hide file tree
Showing 13 changed files with 102 additions and 28 deletions.
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
22 changes: 12 additions & 10 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
{
"name": "Flux Sched Developer Environment",
"dockerFile": "Dockerfile",
"context": "../",
"name": "Flux Sched Developer Environment",
"dockerFile": "Dockerfile",
"context": "../",

"customizations": {
"vscode": {
"settings": {
"terminal.integrated.defaultProfile.linux": "bash"
}
}
"customizations": {
"vscode": {
"settings": {
"terminal.integrated.defaultProfile.linux": "bash"
},
"extensions": [
"ms-vscode.cmake-tools"
]
}
},
"postStartCommand": "git config --global --add safe.directory /workspaces/flux-sched"
}
}
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 to build the go bindings and test binary
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
39 changes: 39 additions & 0 deletions cmake/GolangSimple.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

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})

# ADD_GO_INSTALLABLE_PROGRAM builds a custom go program (primarily for testing)
function(BUILD_GO_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})

# THIS IS NOT USED
# 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}")

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${CMAKE_BINARY_DIR}/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(BUILD_GO_PROGRAM)
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()
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 )
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
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 )
17 changes: 17 additions & 0 deletions resource/reapi/bindings/go/src/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
set(TARGET main)
set(SRCS main.go)
set(CGO_CFLAGS "-I${CMAKE_BINARY_DIR}/resource/reapi/bindings/c")

# This is currently passed but not used because when passed into add_custom_command the spaces are escaped
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")

# This ensures the main binary is cleaned up
set_directory_properties(
PROPERTIES
ADDITIONAL_CLEAN_FILES "${CMAKE_CURRENT_BINARY_DIR}/main"
)

# GO_GET(go_redis github.com/hoisie/redis)
# main main.go
# We add the dependencies at the end so the build can run in parallel and we don't try to build this before they are ready!
BUILD_GO_PROGRAM(${TARGET} ${SRCS} "${CGO_CFLAGS}" "${CGO_LIBRARY_FLAGS}" jobspec_conv reapi_module reapi_cli resource 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
21 changes: 14 additions & 7 deletions src/test/docker/focal-golang/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,20 @@ ARG UID=1000
# Install extra buildrequires for flux-sched:
RUN sudo apt-get update
RUN sudo apt-get -qq install -y --no-install-recommends \
libboost-graph-dev \
libboost-system-dev \
libboost-filesystem-dev \
libboost-regex-dev \
python-yaml \
libyaml-cpp-dev \
libedit-dev
libboost-graph-dev \
libboost-system-dev \
libboost-filesystem-dev \
libboost-regex-dev \
python-yaml \
libyaml-cpp-dev \
ninja-build \
curl \
libedit-dev

# Install cmake for new build system
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 ;\
rm cmake.sh

# Install Golang 1.19.10 for binding tests
RUN wget https://go.dev/dl/go1.19.10.linux-amd64.tar.gz
Expand Down
7 changes: 0 additions & 7 deletions src/test/generate-matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,13 +196,6 @@ def __str__(self):
),
)

# RHEL7 clone
matrix.add_build(
name="el7",
image="el7",
docker_tag=True,
)

# RHEL8 clone
matrix.add_build(
name="el8",
Expand Down
2 changes: 2 additions & 0 deletions t/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# NOTE: skipping tree tests, since they're long broken
# t2000-tree-basic.t
# t2001-tree-real.t

set(ALL_TESTS
t0000-sharness.t
t1001-qmanager-basic.t
Expand Down Expand Up @@ -81,6 +82,7 @@ set(ALL_TESTS
t6002-graph-hwloc.t
t7000-shell-datastaging.t
t8001-util-ion-R.t
t9001-golang-basic.t
)
foreach(test ${ALL_TESTS})
flux_add_test(NAME ${test}
Expand Down

0 comments on commit 4d66306

Please sign in to comment.