From 7ff05a7e08e3b0151ffc43b87dda5ce8c338c0bc Mon Sep 17 00:00:00 2001 From: Lia Stratopoulos <167905060+lia-viam@users.noreply.github.com> Date: Mon, 23 Sep 2024 15:41:49 -0400 Subject: [PATCH 01/20] first attempt conan ci job --- .github/workflows/conan.yml | 165 ++++++++++++++++++++++++++++++++++++ 1 file changed, 165 insertions(+) create mode 100644 .github/workflows/conan.yml diff --git a/.github/workflows/conan.yml b/.github/workflows/conan.yml new file mode 100644 index 000000000..1071e3f9d --- /dev/null +++ b/.github/workflows/conan.yml @@ -0,0 +1,165 @@ +name: Test conan packages + +on: + workflow_dispatch: + +jobs: + build_macos: + if: github.repository_owner == 'viamrobotics' + runs-on: macos-latest + strategy: + fail-fast: false + matrix: + include: + - target: aarch64-apple-darwin + platform: macosx_arm64 + - target: x86_64-apple-darwin + platform: macosx_x86_64 + steps: + - name: Checkout Code + uses: actions/checkout@v4 + + - name: Install dependencies + run: | + brew install cmake + brew install python ninja buf + python -m pip install --user conan + + - name: Build + run: | + # `buf` tries to read a CLI config file that we don't actually use located at + # ~/.config/buf/config.yaml. We don't always have permission to access this + # directory in CI, so we set the `BUF_CONFIG_DIR` to some other value that we + # do have permissions for. See https://github.com/bufbuild/buf/issues/2698 for + # more details. + export BUF_CONFIG_DIR=$(mktemp -d) + conan profile detect + conan create . + + build_linux_ubuntu_jammy: + if: github.repository_owner == 'viamrobotics' + runs-on: ${{ matrix.runs_on }} + container: + image: ${{ matrix.image }} + strategy: + fail-fast: false + matrix: + include: + - target: aarch64-ubuntu-jammy-gnu + platform: linux_aarch64-ubuntu-jammy + image: ubuntu:22.04 + runs_on: buildjet-8vcpu-ubuntu-2204-arm + - target: x86_64-ubuntu-jammy-gnu + platform: linux_x86_64-ubuntu-jammy + image: ubuntu:22.04 + runs_on: buildjet-8vcpu-ubuntu-2204 + + steps: + - name: Checkout Code + uses: actions/checkout@v4 + + - name: Install dependencies + run: | + apt-get update + apt-get -y dist-upgrade + DEBIAN_FRONTEND=noninteractive apt-get -y --no-install-recommends install \ + build-essential \ + ca-certificates \ + curl \ + doxygen \ + g++ \ + gdb \ + git \ + gnupg \ + gpg \ + less \ + ninja-build \ + python3 \ + python3-pip \ + software-properties-common \ + sudo \ + wget \ + + sudo wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | sudo gpg --dearmor - | sudo tee /usr/share/keyrings/kitware-archive-keyring.gpg >/dev/null + sudo echo 'deb [signed-by=/usr/share/keyrings/kitware-archive-keyring.gpg] https://apt.kitware.com/ubuntu/ jammy main' | sudo tee /etc/apt/sources.list.d/kitware.list >/dev/null + + apt-get update + apt-get -y install cmake + + pip install conan + + - name: Create package + shell: bash + run: | + conan profile detect + conan create . + + build_linux_debian: + if: github.repository_owner == 'viamrobotics' + runs-on: ${{ matrix.runs_on }} + container: + image: ${{ matrix.image }} + strategy: + fail-fast: false + matrix: + include: + - target: aarch64-debian-bullseye + platform: linux_aarch64-debian-bullseye + image: debian:bullseye + runs_on: buildjet-8vcpu-ubuntu-2204-arm + - target: x86_64-debian-bullseye + platform: linux_x86_64-debian-bullseye + image: debian:bullseye + runs_on: buildjet-8vcpu-ubuntu-2204 + - target: aarch64-debian-bookworm + platform: linux_aarch64-debian-bookworm + image: debian:bookworm + runs_on: buildjet-8vcpu-ubuntu-2204-arm + - target: x86_64-debian-bookworm + platform: linux_x86_64-debian-bookworm + image: debian:bookworm + runs_on: buildjet-8vcpu-ubuntu-2204 + + steps: + - name: Checkout Code + uses: actions/checkout@v4 + + - name: Install dependencies + run: | + apt-get update + apt-get -y dist-upgrade + DEBIAN_FRONTEND=noninteractive apt-get -y --no-install-recommends install \ + build-essential \ + ca-certificates \ + cmake \ + curl \ + g++ \ + gdb \ + git \ + gnupg \ + gpg \ + less \ + ninja-build \ + python3 \ + python3-pip \ + software-properties-common \ + sudo \ + wget + + pip install conan + + - name: Update CMake for bullseye + if: ${{ matrix.image == 'debian:bullseye' }} + run: | + apt-add-repository -y 'deb http://deb.debian.org/debian bullseye-backports main' + + apt-get update + apt-get -y install cmake + + apt-get -y --no-install-recommends install -t bullseye-backports cmake + + - name: Create package + shell: bash + run: | + conan profile detect + conan create . From b04fc36d60a17c910223a62bc191ebf3aaf8cdd0 Mon Sep 17 00:00:00 2001 From: Lia Stratopoulos <167905060+lia-viam@users.noreply.github.com> Date: Mon, 23 Sep 2024 15:42:14 -0400 Subject: [PATCH 02/20] remove git --- .github/workflows/conan.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/conan.yml b/.github/workflows/conan.yml index 1071e3f9d..d4d03f870 100644 --- a/.github/workflows/conan.yml +++ b/.github/workflows/conan.yml @@ -69,7 +69,6 @@ jobs: doxygen \ g++ \ gdb \ - git \ gnupg \ gpg \ less \ @@ -135,7 +134,6 @@ jobs: curl \ g++ \ gdb \ - git \ gnupg \ gpg \ less \ From 95f407e289a2705cd923fa8aed60415423ee1179 Mon Sep 17 00:00:00 2001 From: Lia Stratopoulos <167905060+lia-viam@users.noreply.github.com> Date: Tue, 24 Sep 2024 14:53:46 -0400 Subject: [PATCH 03/20] comment out repo owner --- .github/workflows/conan.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/conan.yml b/.github/workflows/conan.yml index d4d03f870..d4278b0b6 100644 --- a/.github/workflows/conan.yml +++ b/.github/workflows/conan.yml @@ -5,7 +5,7 @@ on: jobs: build_macos: - if: github.repository_owner == 'viamrobotics' + # if: github.repository_owner == 'viamrobotics' runs-on: macos-latest strategy: fail-fast: false @@ -37,7 +37,7 @@ jobs: conan create . build_linux_ubuntu_jammy: - if: github.repository_owner == 'viamrobotics' + # if: github.repository_owner == 'viamrobotics' runs-on: ${{ matrix.runs_on }} container: image: ${{ matrix.image }} @@ -94,7 +94,7 @@ jobs: conan create . build_linux_debian: - if: github.repository_owner == 'viamrobotics' + # if: github.repository_owner == 'viamrobotics' runs-on: ${{ matrix.runs_on }} container: image: ${{ matrix.image }} From c5bc9a6d386d8720deca78c9fce1cbae292d39d9 Mon Sep 17 00:00:00 2001 From: Lia Stratopoulos <167905060+lia-viam@users.noreply.github.com> Date: Tue, 24 Sep 2024 15:00:50 -0400 Subject: [PATCH 04/20] global install --- .github/workflows/conan.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/conan.yml b/.github/workflows/conan.yml index d4278b0b6..3634a4869 100644 --- a/.github/workflows/conan.yml +++ b/.github/workflows/conan.yml @@ -23,7 +23,7 @@ jobs: run: | brew install cmake brew install python ninja buf - python -m pip install --user conan + python -m pip install conan - name: Build run: | From be04812206a50a7209cdacd867387e71fef5011b Mon Sep 17 00:00:00 2001 From: Lia Stratopoulos <167905060+lia-viam@users.noreply.github.com> Date: Tue, 24 Sep 2024 15:09:15 -0400 Subject: [PATCH 05/20] always set build = missing --- .github/workflows/conan.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/conan.yml b/.github/workflows/conan.yml index 3634a4869..52ca377de 100644 --- a/.github/workflows/conan.yml +++ b/.github/workflows/conan.yml @@ -34,7 +34,7 @@ jobs: # more details. export BUF_CONFIG_DIR=$(mktemp -d) conan profile detect - conan create . + conan create . --build=missing build_linux_ubuntu_jammy: # if: github.repository_owner == 'viamrobotics' @@ -91,7 +91,7 @@ jobs: shell: bash run: | conan profile detect - conan create . + conan create . --build=missing build_linux_debian: # if: github.repository_owner == 'viamrobotics' @@ -160,4 +160,4 @@ jobs: shell: bash run: | conan profile detect - conan create . + conan create . --build=missing From e5272e1d5d7bc2c204af267450dcf8849992a28f Mon Sep 17 00:00:00 2001 From: Lia Stratopoulos <167905060+lia-viam@users.noreply.github.com> Date: Wed, 9 Oct 2024 11:27:21 -0400 Subject: [PATCH 06/20] update conanfile and cml for whole archive --- conanfile.py | 17 ++++++++++++++++- src/viam/sdk/CMakeLists.txt | 2 +- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/conanfile.py b/conanfile.py index 0ac8f875c..98fe462cc 100644 --- a/conanfile.py +++ b/conanfile.py @@ -1,6 +1,8 @@ from conan import ConanFile from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout from conan.tools.files import load +from conan.tools.apple import is_apple_os +import os import re class ViamCppSdkRecipe(ConanFile): @@ -81,9 +83,10 @@ def package(self): def package_info(self): self.cpp_info.components["viam_rust_utils"].libs = ["viam_rust_utils"] + + self.cpp_info.components["viamsdk"].libs = ["viamsdk"] for component in ["viamsdk", "viamapi"]: - self.cpp_info.components[component].libs = [component] self.cpp_info.components[component].set_property("cmake_target_name", "viam-cpp-sdk::{}".format(component)) self.cpp_info.components[component].set_property("pkg_config_name", "viam-cpp-sdk-lib{}".format(component)) self.cpp_info.components[component].requires = ["grpc::grpc++", "protobuf::libprotobuf"] @@ -95,6 +98,18 @@ def package_info(self): self.cpp_info.components["viamapi"].includedirs.append("include/viam/api") + if self.options.shared: + self.cpp_info.components["viamapi"].libs = ["viamapi"] + else: + lib_folder = os.path.join(self.package_folder, "lib") + lib_fullpath = os.path.join(lib_folder, "libviamapi.a") + if is_apple_os(self): + whole_archive = f"-Wl,-force_load,{lib_fullpath}" + else: + whole_archive = f"-Wl,--push-state,--whole-archive,{lib_fullpath},--pop-state" + self.cpp_info.components["viamapi"].exelinkflags.append(whole_archive) + self.cpp_info.components["viamapi"].sharedlinkflags.append(whole_archive) + self.cpp_info.components["viamsdk"].requires.extend([ "viamapi", "boost::headers", diff --git a/src/viam/sdk/CMakeLists.txt b/src/viam/sdk/CMakeLists.txt index 04077c991..c0cda1821 100644 --- a/src/viam/sdk/CMakeLists.txt +++ b/src/viam/sdk/CMakeLists.txt @@ -228,7 +228,7 @@ target_link_directories(viamsdk ) target_link_libraries(viamsdk - PUBLIC viam-cpp-sdk::viamapi + PUBLIC "$" PUBLIC ${VIAMCPPSDK_GRPCXX_LIBRARIES} PUBLIC ${VIAMCPPSDK_GRPC_LIBRARIES} PUBLIC ${VIAMCPPSDK_PROTOBUF_LIBRARIES} From 53607d80b3e260927974bca0bcad7ab3350acf77 Mon Sep 17 00:00:00 2001 From: Lia Stratopoulos <167905060+lia-viam@users.noreply.github.com> Date: Fri, 11 Oct 2024 10:15:23 -0400 Subject: [PATCH 07/20] try to decouple example and test building --- CMakeLists.txt | 10 ++-------- .../examples/modules/complex/CMakeLists.txt | 18 ++++++++++-------- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bfe9585cc..69cb7a6ee 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -129,14 +129,8 @@ option(VIAMCPPSDK_CLANG_TIDY "Run the clang-tidy linter" OFF) # The following options are only defined if this project is not being included as a subproject if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) - include(CMakeDependentOption) - option(VIAMCPPSDK_BUILD_EXAMPLES "Build the example executables (requires building tests too)" ON) - - # Note that the complex module example requires the testing library and adds its tests to the unit - # test suite. Thus you can only disable tests if examples are also disabled. - # The call below says don't give the user the option to disable tests unless examples are already - # disabled, and default to building the tests in either case. - cmake_dependent_option(VIAMCPPSDK_BUILD_TESTS "Build the unit test suite" ON "NOT VIAMCPPSDK_BUILD_EXAMPLES" ON) + option(VIAMCPPSDK_BUILD_EXAMPLES "Build the example executables" ON) + option(VIAMCPPSDK_BUILD_TESTS "Build the example executables" ON) endif() diff --git a/src/viam/examples/modules/complex/CMakeLists.txt b/src/viam/examples/modules/complex/CMakeLists.txt index 51f63c044..6ac850332 100644 --- a/src/viam/examples/modules/complex/CMakeLists.txt +++ b/src/viam/examples/modules/complex/CMakeLists.txt @@ -140,11 +140,13 @@ install( # writing their own modules. We are simply integrating tests from # `test_complex_module.cpp` into the Viam C++ SDK testing suite. -enable_testing() -viamcppsdk_add_boost_test(test_complex_module.cpp) -target_sources(test_complex_module - PRIVATE - gizmo/impl.cpp - summation/impl.cpp -) -target_link_libraries(test_complex_module complex_module_sources) +if (VIAMCPPSDK_BUILD_TESTS) + enable_testing() + viamcppsdk_add_boost_test(test_complex_module.cpp) + target_sources(test_complex_module + PRIVATE + gizmo/impl.cpp + summation/impl.cpp + ) + target_link_libraries(test_complex_module complex_module_sources) +endif() From 7a8322b0762ecc0c7d7f816b4c6dda75e0a89e4c Mon Sep 17 00:00:00 2001 From: Lia Stratopoulos <167905060+lia-viam@users.noreply.github.com> Date: Tue, 15 Oct 2024 14:00:47 -0400 Subject: [PATCH 08/20] make test package test proper operation of module --- test_package/conanfile.py | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/test_package/conanfile.py b/test_package/conanfile.py index 408f6b4b5..d3627813a 100644 --- a/test_package/conanfile.py +++ b/test_package/conanfile.py @@ -1,5 +1,5 @@ +import subprocess import os -from io import StringIO from conan import ConanFile from conan.errors import ConanException @@ -23,8 +23,22 @@ def layout(self): def test(self): if can_run(self): - cmd = os.path.join(self.cpp.build.bindir, "example_module") - stderr = StringIO() - self.run(cmd, env='conanrun', stderr=stderr, ignore_errors=True) - if "main failed with exception:" not in stderr.getvalue(): - raise ConanException("Unexpected error output from test") + sock = "fake-socket-path" + + cmd = os.path.join(self.cpp.build.bindir, f"example_module {sock}") + + # the ConanFile run method is a wrapper around Popen, but it only returns the retcode. + # A properly intialized module waits indefinitely on a signal, so we have to use Popen manually. + proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, text=True) + + out = None + + try: + out = proc.communicate(timeout=2)[0] + except subprocess.TimeoutExpired: + proc.terminate() + out = proc.communicate()[0] + pass + + if f"Module listening on {sock}" not in out: + raise ConanException(f"Simple example failed to start module listening") From b625673ba1ceae51a350d2ed7f545e5ce4d65219 Mon Sep 17 00:00:00 2001 From: Lia Stratopoulos <167905060+lia-viam@users.noreply.github.com> Date: Tue, 15 Oct 2024 15:03:26 -0400 Subject: [PATCH 09/20] guard whole_archive with if build_shared_libs --- src/viam/sdk/CMakeLists.txt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/viam/sdk/CMakeLists.txt b/src/viam/sdk/CMakeLists.txt index c0cda1821..3ed83a7d5 100644 --- a/src/viam/sdk/CMakeLists.txt +++ b/src/viam/sdk/CMakeLists.txt @@ -227,8 +227,13 @@ target_link_directories(viamsdk "$" ) +if (BUILD_SHARED_LIBS) + target_link_libraries(viamsdk PUBLIC viam-cpp-sdk::viamapi) +else() + target_link_libraries(viamsdk PUBLIC "$") +endif() + target_link_libraries(viamsdk - PUBLIC "$" PUBLIC ${VIAMCPPSDK_GRPCXX_LIBRARIES} PUBLIC ${VIAMCPPSDK_GRPC_LIBRARIES} PUBLIC ${VIAMCPPSDK_PROTOBUF_LIBRARIES} From 1414fa99c00dbf2a25582c15601fae2b91881abb Mon Sep 17 00:00:00 2001 From: Lia Stratopoulos <167905060+lia-viam@users.noreply.github.com> Date: Tue, 15 Oct 2024 15:04:08 -0400 Subject: [PATCH 10/20] test module startup in examples CI --- etc/docker/tests/run_test.sh | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/etc/docker/tests/run_test.sh b/etc/docker/tests/run_test.sh index 83fbc51a6..57bf45a1f 100755 --- a/etc/docker/tests/run_test.sh +++ b/etc/docker/tests/run_test.sh @@ -22,13 +22,22 @@ popd # Check with both CMake and make/pkg-config that we can build the example # and have it exit with the expected error message. +run_module() { + ./example_module fake-socket-path > module-out-temp.txt & + MODULE_PID=$! + sleep 2 + kill ${MODULE_PID} + grep 'Module listening' module-out-temp.txt + return $? +} + cd ../src/viam/examples/project pushd cmake cmake . -G Ninja # Just do an in-source build to save path fiddling ninja all -[ $(./example_module 2>&1 | grep 'main failed with exception:' -c) = 1 ] +run_module popd pushd pkg-config PKG_CONFIG_PATH=${INSTALL_DIR}/lib/pkgconfig make all -[ $(./example_module 2>&1 | grep 'main failed with exception:' -c) = 1 ] +run_module popd From 616e990af092564ca0e587f243e3aca53dbd5d46 Mon Sep 17 00:00:00 2001 From: Lia Stratopoulos <167905060+lia-viam@users.noreply.github.com> Date: Tue, 15 Oct 2024 15:04:23 -0400 Subject: [PATCH 11/20] update comment --- etc/docker/tests/run_test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/etc/docker/tests/run_test.sh b/etc/docker/tests/run_test.sh index 57bf45a1f..8f7953255 100755 --- a/etc/docker/tests/run_test.sh +++ b/etc/docker/tests/run_test.sh @@ -20,7 +20,7 @@ popd # Test that example_module builds and runs with the SDK install from above. # Check with both CMake and make/pkg-config that we can build the example -# and have it exit with the expected error message. +# and have it start listening. run_module() { ./example_module fake-socket-path > module-out-temp.txt & From 27b850691ced2df201336225a2463e576edd13dd Mon Sep 17 00:00:00 2001 From: Lia Stratopoulos <167905060+lia-viam@users.noreply.github.com> Date: Tue, 15 Oct 2024 15:39:24 -0400 Subject: [PATCH 12/20] update generated pkg-config files --- src/viam/api/CMakeLists.txt | 7 +++++++ src/viam/api/config/viam-cpp-sdk-libviamapi.pc.in | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/viam/api/CMakeLists.txt b/src/viam/api/CMakeLists.txt index 1b33312e7..f40e632fb 100644 --- a/src/viam/api/CMakeLists.txt +++ b/src/viam/api/CMakeLists.txt @@ -459,6 +459,13 @@ install( # incantation to get CMake to expand the various generator expressions # in the "INSTALL" context. +if (NOT BUILD_SHARED_LIBS) + # Careful readers will note that pkg-config gets a more correct version of this than CMake does, + # because whole-archive is a link property of viamapi itself + set(VIAMCPPSDK_VIAM_API_LINK_PREFIX "-Wl,--push-state,--whole-archive") + set(VIAMCPPSDK_VIAM_API_LINK_SUFFIX "-Wl,--pop-state") +endif() + configure_file( config/viam-cpp-sdk-libviamapi.pc.in config/viam-cpp-sdk-libviamapi.pc diff --git a/src/viam/api/config/viam-cpp-sdk-libviamapi.pc.in b/src/viam/api/config/viam-cpp-sdk-libviamapi.pc.in index a55612130..0965441a2 100644 --- a/src/viam/api/config/viam-cpp-sdk-libviamapi.pc.in +++ b/src/viam/api/config/viam-cpp-sdk-libviamapi.pc.in @@ -8,6 +8,6 @@ Description: @PROJECT_DESCRIPTION@ URL: @PROJECT_HOMEPAGE_URL@ Version: @PROJECT_VERSION@ Requires: grpc++ >= @VIAMCPPSDK_GRPCXX_VERSION@ protobuf >= @VIAMCPPSDK_PROTOBUF_VERSION@ -Libs: -Wl,-rpath,${libdir} -L${libdir} -L@Boost_LIBRARY_DIRS@ -lviamapi +Libs: -Wl,-rpath,${libdir} -L${libdir} -L@Boost_LIBRARY_DIRS@ @VIAMCPPSDK_VIAM_API_LINK_PREFIX@ -lviamapi @VIAMCPPSDK_VIAM_API_LINK_SUFFIX@ Cflags: -I${base_includedir} -I${deep_includedir} From 2d2004cb76eb07d28e3cf16fb8077c452b0ddf85 Mon Sep 17 00:00:00 2001 From: Lia Stratopoulos <167905060+lia-viam@users.noreply.github.com> Date: Tue, 15 Oct 2024 16:37:53 -0400 Subject: [PATCH 13/20] try adding shared/not shared to conan matrix --- .github/workflows/conan.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.github/workflows/conan.yml b/.github/workflows/conan.yml index dd37a985d..be51b40ca 100644 --- a/.github/workflows/conan.yml +++ b/.github/workflows/conan.yml @@ -72,10 +72,12 @@ jobs: platform: linux_aarch64-ubuntu-jammy image: ubuntu:22.04 runs_on: buildjet-8vcpu-ubuntu-2204-arm + shared: 0 - target: x86_64-ubuntu-jammy-gnu platform: linux_x86_64-ubuntu-jammy image: ubuntu:22.04 runs_on: buildjet-8vcpu-ubuntu-2204 + shared: [0, 1] steps: - name: Checkout Code @@ -111,11 +113,19 @@ jobs: pip install conan - name: Create package + if: ${{ matrix.shared }} == 1 shell: bash run: | conan profile detect conan create . --build=missing -s compiler.cppstd=14 + - name: Create package + if: ${{ matrix.shared }} == 0 + shell: bash + run: | + conan profile detect + conan create . --build=missing -s compiler.cppstd=14 -o "*:shared=False" -o "&:shared=False" + build_linux_debian: if: github.repository_owner == 'viamrobotics' needs: [prepare] From 70ee7a632b6baa8a9d7f14f852d5ad265bc0a7eb Mon Sep 17 00:00:00 2001 From: Lia Stratopoulos <167905060+lia-viam@users.noreply.github.com> Date: Wed, 16 Oct 2024 12:39:28 -0400 Subject: [PATCH 14/20] revert conan --- .github/workflows/conan.yml | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/.github/workflows/conan.yml b/.github/workflows/conan.yml index be51b40ca..dd37a985d 100644 --- a/.github/workflows/conan.yml +++ b/.github/workflows/conan.yml @@ -72,12 +72,10 @@ jobs: platform: linux_aarch64-ubuntu-jammy image: ubuntu:22.04 runs_on: buildjet-8vcpu-ubuntu-2204-arm - shared: 0 - target: x86_64-ubuntu-jammy-gnu platform: linux_x86_64-ubuntu-jammy image: ubuntu:22.04 runs_on: buildjet-8vcpu-ubuntu-2204 - shared: [0, 1] steps: - name: Checkout Code @@ -113,19 +111,11 @@ jobs: pip install conan - name: Create package - if: ${{ matrix.shared }} == 1 shell: bash run: | conan profile detect conan create . --build=missing -s compiler.cppstd=14 - - name: Create package - if: ${{ matrix.shared }} == 0 - shell: bash - run: | - conan profile detect - conan create . --build=missing -s compiler.cppstd=14 -o "*:shared=False" -o "&:shared=False" - build_linux_debian: if: github.repository_owner == 'viamrobotics' needs: [prepare] From 53361921e5eb6aa800332996d6fcceb42f01e4e4 Mon Sep 17 00:00:00 2001 From: Lia Stratopoulos <167905060+lia-viam@users.noreply.github.com> Date: Wed, 16 Oct 2024 14:01:30 -0400 Subject: [PATCH 15/20] add matrix to build shared and static for test workflow --- .github/workflows/test.yml | 7 ++++++- etc/docker/tests/run_test.sh | 4 +++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 19cd55917..7cdcc4410 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -10,6 +10,11 @@ jobs: runs-on: ubuntu-latest container: image: ghcr.io/viamrobotics/canon:amd64 + strategy: + matrix: + include: + - BUILD_SHARED: ON + - BUILD_SHARED: OFF steps: - uses: actions/checkout@v4 ########################################### @@ -18,4 +23,4 @@ jobs: - name: build-docker-test run: | docker build -t cpp . -f etc/docker/tests/Dockerfile.debian.bullseye - docker run --rm -i -w /tmp cpp /bin/bash + docker run -e BUILD_SHARED=${{ matrix.BUILD_SHARED }} --rm -i -w /tmp cpp /bin/bash diff --git a/etc/docker/tests/run_test.sh b/etc/docker/tests/run_test.sh index 8f7953255..e17a66fc1 100755 --- a/etc/docker/tests/run_test.sh +++ b/etc/docker/tests/run_test.sh @@ -6,7 +6,9 @@ cd build cmake .. -G Ninja -DVIAMCPPSDK_USE_DYNAMIC_PROTOS=ON \ -DVIAMCPPSDK_OFFLINE_PROTO_GENERATION=ON \ -DVIAMCPPSDK_SANITIZED_BUILD=ON \ - -DVIAMCPPSDK_CLANG_TIDY=ON + -DVIAMCPPSDK_CLANG_TIDY=ON \ + -DBUILD_SHARED_LIBS=$BUILD_SHARED + ninja all ninja install INSTALL_DIR="$(pwd)/install" From a340846f5b6b6f804478ec80c5421f7972ba4ec7 Mon Sep 17 00:00:00 2001 From: Lia Stratopoulos <167905060+lia-viam@users.noreply.github.com> Date: Wed, 16 Oct 2024 16:04:21 -0400 Subject: [PATCH 16/20] only run sanitizers for shared --- etc/docker/tests/run_test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/etc/docker/tests/run_test.sh b/etc/docker/tests/run_test.sh index e17a66fc1..9e1b719b2 100755 --- a/etc/docker/tests/run_test.sh +++ b/etc/docker/tests/run_test.sh @@ -5,7 +5,7 @@ mkdir build cd build cmake .. -G Ninja -DVIAMCPPSDK_USE_DYNAMIC_PROTOS=ON \ -DVIAMCPPSDK_OFFLINE_PROTO_GENERATION=ON \ - -DVIAMCPPSDK_SANITIZED_BUILD=ON \ + -DVIAMCPPSDK_SANITIZED_BUILD=$BUILD_SHARED \ -DVIAMCPPSDK_CLANG_TIDY=ON \ -DBUILD_SHARED_LIBS=$BUILD_SHARED From 7c5fe453c03be0369ff869a6c99573e267b60765 Mon Sep 17 00:00:00 2001 From: Lia Stratopoulos <167905060+lia-viam@users.noreply.github.com> Date: Thu, 17 Oct 2024 13:00:43 -0400 Subject: [PATCH 17/20] update shared libs docs --- CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 69cb7a6ee..8067dac91 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -51,7 +51,9 @@ project(viam-cpp-sdk # # Enabled by default so that we produce a # modern SDK, this option can be set to `OFF` to build a static -# library. Note that this may result in non-functional examples. +# library. +# Note that the pkg-config files installed by the project do not work +# for a static build; please use Conan for more robust pkg-config support. # option(BUILD_SHARED_LIBS "If enabled, build shared libraries" ON) From 8df0f694ae6cb4b25e0a08b72c869ae8c3d98f7a Mon Sep 17 00:00:00 2001 From: Lia Stratopoulos <167905060+lia-viam@users.noreply.github.com> Date: Thu, 17 Oct 2024 13:01:05 -0400 Subject: [PATCH 18/20] only do pkg config for shared --- etc/docker/tests/run_test.sh | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/etc/docker/tests/run_test.sh b/etc/docker/tests/run_test.sh index 9e1b719b2..2f61050ec 100755 --- a/etc/docker/tests/run_test.sh +++ b/etc/docker/tests/run_test.sh @@ -39,7 +39,11 @@ cmake . -G Ninja # Just do an in-source build to save path fiddling ninja all run_module popd -pushd pkg-config -PKG_CONFIG_PATH=${INSTALL_DIR}/lib/pkgconfig make all -run_module -popd + +if [ ${BUILD_SHARED} = "ON" ] +then + pushd pkg-config + PKG_CONFIG_PATH=${INSTALL_DIR}/lib/pkgconfig make all + run_module + popd +fi From fa3d7b99e8eaf7eda9d29408a9486da80403a23e Mon Sep 17 00:00:00 2001 From: Lia Stratopoulos <167905060+lia-viam@users.noreply.github.com> Date: Thu, 17 Oct 2024 13:04:44 -0400 Subject: [PATCH 19/20] remove api pkg-config static build logic --- src/viam/api/CMakeLists.txt | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/viam/api/CMakeLists.txt b/src/viam/api/CMakeLists.txt index f40e632fb..1b33312e7 100644 --- a/src/viam/api/CMakeLists.txt +++ b/src/viam/api/CMakeLists.txt @@ -459,13 +459,6 @@ install( # incantation to get CMake to expand the various generator expressions # in the "INSTALL" context. -if (NOT BUILD_SHARED_LIBS) - # Careful readers will note that pkg-config gets a more correct version of this than CMake does, - # because whole-archive is a link property of viamapi itself - set(VIAMCPPSDK_VIAM_API_LINK_PREFIX "-Wl,--push-state,--whole-archive") - set(VIAMCPPSDK_VIAM_API_LINK_SUFFIX "-Wl,--pop-state") -endif() - configure_file( config/viam-cpp-sdk-libviamapi.pc.in config/viam-cpp-sdk-libviamapi.pc From c9abe9af34b22e3459d85661fc67afe1d1c2102f Mon Sep 17 00:00:00 2001 From: Lia Stratopoulos <167905060+lia-viam@users.noreply.github.com> Date: Thu, 17 Oct 2024 13:05:25 -0400 Subject: [PATCH 20/20] revert pc changes --- src/viam/api/config/viam-cpp-sdk-libviamapi.pc.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/viam/api/config/viam-cpp-sdk-libviamapi.pc.in b/src/viam/api/config/viam-cpp-sdk-libviamapi.pc.in index 0965441a2..a55612130 100644 --- a/src/viam/api/config/viam-cpp-sdk-libviamapi.pc.in +++ b/src/viam/api/config/viam-cpp-sdk-libviamapi.pc.in @@ -8,6 +8,6 @@ Description: @PROJECT_DESCRIPTION@ URL: @PROJECT_HOMEPAGE_URL@ Version: @PROJECT_VERSION@ Requires: grpc++ >= @VIAMCPPSDK_GRPCXX_VERSION@ protobuf >= @VIAMCPPSDK_PROTOBUF_VERSION@ -Libs: -Wl,-rpath,${libdir} -L${libdir} -L@Boost_LIBRARY_DIRS@ @VIAMCPPSDK_VIAM_API_LINK_PREFIX@ -lviamapi @VIAMCPPSDK_VIAM_API_LINK_SUFFIX@ +Libs: -Wl,-rpath,${libdir} -L${libdir} -L@Boost_LIBRARY_DIRS@ -lviamapi Cflags: -I${base_includedir} -I${deep_includedir}