diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index fd3990326..405a44667 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -12,7 +12,7 @@ on: description: set to true to build without clang-tidy (2x faster) jobs: - run-tests: + test_ubuntu: if: github.repository_owner == 'viamrobotics' runs-on: ubuntu-latest container: ghcr.io/viamrobotics/cpp-base:bullseye-amd64 @@ -42,3 +42,40 @@ jobs: - name: test working-directory: build run: ../etc/docker/tests/run_test.sh + test_windows: + if: github.repository_owner == 'viamrobotics' + runs-on: windows-latest + strategy: + fail-fast: false + matrix: + include: + - target: x86_64-windows + platform: windows_x86_64 + steps: + - name: Checkout Code + uses: actions/checkout@v4 + with: + ref: ${{ needs.prepare.outputs.sha }} + + - name: Install dependencies + run: choco install -y conan git + + - name: Build SDK + shell: powershell + run: | + Import-Module $env:ChocolateyInstall\helpers\chocolateyProfile.psm1 + refreshenv + conan profile detect + conan install . --build=missing -o "&:shared=False" + cmake . --preset conan-default -DVIAMCPPSDK_BUILD_EXAMPLES=ON + cmake --build --preset=conan-release --target ALL_BUILD install -j 8 + env: + CONAN_USER_HOME: c:/cache + CONAN_USER_HOME_SHORT: c:/cache/conan_shortpaths + + - name: Test examples + shell: powershell + run: | + Start-Job -Init ([ScriptBlock]::Create("Set-Location '$pwd/build/install/bin'")) -ScriptBlock { .\simple_module.exe asdf 2>&1 > output.txt} | Wait-Job -Timeout 2 | Receive-Job + if (-not $(Select-String -Pattern "Module listening" -Path ./build/install/bin/output.txt)) { throw "Module did not start listening" } + diff --git a/src/viam/api/CMakeLists.txt b/src/viam/api/CMakeLists.txt index 72f03567b..46e04c92a 100644 --- a/src/viam/api/CMakeLists.txt +++ b/src/viam/api/CMakeLists.txt @@ -55,46 +55,9 @@ list(JOIN BUF_PROTO_COMPONENTS , BUF_PROTO_COMPONENTS_JOINED) if (VIAMCPPSDK_USE_DYNAMIC_PROTOS) - # Look for the `buf` command in the usual places, and use it if - # found. If we can't find it, try to download it and use that. - # - # TODO: File an upstream issue with `buf.build` to add - # `find_package` support for it, then use it. - # - find_program(BUF_COMMAND buf) - if (NOT BUF_COMMAND) - - set(HOST_SYSTEM_PROCESSOR_FOR_BUF_DOWNLOAD ${CMAKE_HOST_SYSTEM_PROCESSOR}) - if (CMAKE_HOST_WIN32) - if (HOST_SYSTEM_PROCESSOR_FOR_BUF_DOWNLOAD STREQUAL "AMD64") - set(HOST_SYSTEM_PROCESSOR_FOR_BUF_DOWNLOAD x86_64) - elseif (HOST_SYSTEM_PROCESSOR_FOR_BUF_DOWNLOAD STREQUAL "ARM64") - set(HOST_SYSTEM_PROCESSOR_FOR_BUF_DOWNLOAD arm64) - else() - message(FATAL_ERROR "Unknown Windows platform to correct buf download URL: ${HOST_SYSTEM_PROCESSOR_FOR_BUF_DOWNLOAD}") - endif() - endif() - - set(BUF_DOWNLOAD_URL https://github.com/bufbuild/buf/releases/latest/download/buf-${CMAKE_HOST_SYSTEM_NAME}-${HOST_SYSTEM_PROCESSOR_FOR_BUF_DOWNLOAD}${CMAKE_HOST_EXECUTABLE_SUFFIX}) - - file( - DOWNLOAD - ${BUF_DOWNLOAD_URL} - ${CMAKE_CURRENT_BINARY_DIR}/buf_latest${CMAKE_HOST_EXECUTABLE_SUFFIX} - STATUS buf_status - ) - list(GET buf_status 0 buf_status_code) - list(GET buf_status 1 buf_status_string) - - if(NOT buf_status_code EQUAL 0) - message(FATAL_ERROR "No local `buf` program found (try setting PATH?) and failed to download: ${buf_status_string} for ${BUF_DOWNLOAD_URL}") - endif() - - set(BUF_COMMAND ${CMAKE_CURRENT_BINARY_DIR}/buf_latest${CMAKE_HOST_EXECUTABLE_SUFFIX}) - file(CHMOD ${BUF_COMMAND} PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE) - endif() + viamcppsdk_get_buf() - # TODO: IDeally we could just generate to `CMAKE_CURRENT_BINARY_DIR` + # TODO: Ideally we could just generate to `CMAKE_CURRENT_BINARY_DIR` # and everything would work just fine. However, that directory also # has intermediate cmake state in it, so we can't use it as a source # for a directory copy to update the static protos, as we do diff --git a/src/viam/cmake/viamcppsdk_utils.cmake b/src/viam/cmake/viamcppsdk_utils.cmake index 82957747d..ff31d9129 100644 --- a/src/viam/cmake/viamcppsdk_utils.cmake +++ b/src/viam/cmake/viamcppsdk_utils.cmake @@ -25,3 +25,50 @@ function(viamcppsdk_link_viam_api TARGET_LIBRARY) target_link_libraries(${TARGET_LIBRARY} ${ARGV1} "$") endif() endfunction() + +# Look for the `buf` command in the usual places, and use it if +# found. If we can't find it, try to download it and use that. +# +# TODO: File an upstream issue with `buf.build` to add +# `find_package` support for it, then use it. +# +function(viamcppsdk_get_buf) + if (BUF_COMMAND) + return() + endif() + + find_program(BUF_COMMAND buf) + if (BUF_COMMAND) + return() + endif() + + set(HOST_SYSTEM_PROCESSOR_FOR_BUF_DOWNLOAD ${CMAKE_HOST_SYSTEM_PROCESSOR}) + if (CMAKE_HOST_WIN32) + if (HOST_SYSTEM_PROCESSOR_FOR_BUF_DOWNLOAD STREQUAL "AMD64") + set(HOST_SYSTEM_PROCESSOR_FOR_BUF_DOWNLOAD x86_64) + elseif (HOST_SYSTEM_PROCESSOR_FOR_BUF_DOWNLOAD STREQUAL "ARM64") + set(HOST_SYSTEM_PROCESSOR_FOR_BUF_DOWNLOAD arm64) + else() + message(FATAL_ERROR "Unknown Windows platform to correct buf download URL: ${HOST_SYSTEM_PROCESSOR_FOR_BUF_DOWNLOAD}") + endif() + endif() + + set(BUF_DOWNLOAD_URL https://github.com/bufbuild/buf/releases/latest/download/buf-${CMAKE_HOST_SYSTEM_NAME}-${HOST_SYSTEM_PROCESSOR_FOR_BUF_DOWNLOAD}${CMAKE_HOST_EXECUTABLE_SUFFIX}) + + file( + DOWNLOAD + ${BUF_DOWNLOAD_URL} + ${CMAKE_CURRENT_BINARY_DIR}/buf_latest${CMAKE_HOST_EXECUTABLE_SUFFIX} + STATUS buf_status + ) + + list(GET buf_status 0 buf_status_code) + list(GET buf_status 1 buf_status_string) + + if(NOT buf_status_code EQUAL 0) + message(FATAL_ERROR "No local `buf` program found (try setting PATH?) and failed to download: ${buf_status_string} for ${BUF_DOWNLOAD_URL}") + endif() + + set(BUF_COMMAND ${CMAKE_CURRENT_BINARY_DIR}/buf_latest${CMAKE_HOST_EXECUTABLE_SUFFIX} CACHE INTERNAL "buf command") + file(CHMOD ${BUF_COMMAND} PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE) +endfunction() diff --git a/src/viam/examples/modules/complex/CMakeLists.txt b/src/viam/examples/modules/complex/CMakeLists.txt index d8ad9bc5f..2dd6bbdc1 100644 --- a/src/viam/examples/modules/complex/CMakeLists.txt +++ b/src/viam/examples/modules/complex/CMakeLists.txt @@ -36,26 +36,9 @@ set(MODULE_PROTO_OUTPUT_FILES ${MODULE_PROTO_GEN_DIR}/summation.pb.h ) -# Look for the `buf` command in the usual places, and use it if found. If we -# can't find it, try to download it and use that. -find_program(BUF_COMMAND buf) -if (NOT BUF_COMMAND) - file( - DOWNLOAD - https://github.com/bufbuild/buf/releases/latest/download/buf-${CMAKE_HOST_SYSTEM_NAME}-${CMAKE_HOST_SYSTEM_PROCESSOR} - ${CMAKE_CURRENT_BINARY_DIR}/buf_latest - STATUS buf_status - ) - list(GET buf_status 0 buf_status_code) - list(GET buf_status 1 buf_status_string) - - if(NOT buf_status_code EQUAL 0) - message(FATAL_ERROR "No local `buf` program found (try setting PATH?) and failed to download: ${buf_status_string}") - endif() - - set(BUF_COMMAND ${CMAKE_CURRENT_BINARY_DIR}/buf_latest) - file(CHMOD ${BUF_COMMAND} PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE) -endif() +# Try to find buf in the path or get it online. +# See the definition of this function for logic that can be adapted to other project files. +viamcppsdk_get_buf() if ((NOT VIAMCPPSDK_OFFLINE_PROTO_GENERATION) AND VIAMCPPSDK_BUF_REMOTE_PLUGIN_SUPPORTED) configure_file(