Skip to content

Commit 40d6135

Browse files
authored
Fix conan shared builds and conan CI (#309)
1 parent 69e1758 commit 40d6135

File tree

3 files changed

+45
-26
lines changed

3 files changed

+45
-26
lines changed

.github/workflows/conan.yml

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
name: Test conan packages
22

33
on:
4-
# Run weekdays at 11:15pm UTC, and specify below to only run if there's been new commits
4+
# Runs for PRs that directly change conan code, and weekdays at 11:15pm UTC.
5+
# Additional logic in the prepare job below makes it so scheduled builds only run
6+
# on new commits.
57
schedule:
68
- cron: "15 11 * * 1-5"
79
workflow_dispatch:
10+
pull_request:
11+
paths:
12+
- conanfile.py
13+
- test_package/conanfile.py
814

915
jobs:
1016
prepare:
@@ -13,17 +19,24 @@ jobs:
1319
steps:
1420
- name: Checkout Code
1521
uses: actions/checkout@v4
16-
17-
- name: Get new commit count
18-
id: new_commit_count
19-
shell: bash
20-
run: echo "commit_count=$(git log --oneline --since '24 hours ago' | wc -l)" >> $GITHUB_OUTPUT
21-
22-
- name: Cancelling scheduled build with no new commits
23-
uses: andymckay/[email protected]
22+
- name: Get current git info
23+
if: github.event_name == 'schedule'
24+
id: git_info
25+
run: |
26+
echo "current_commit=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
27+
echo "current_branch=$(git branch --show-current)" >> $GITHUB_OUTPUT
28+
- name: Get last successful commit
29+
if: github.event_name == 'schedule'
30+
id: last_successful_commit
31+
uses: nrwl/last-successful-commit-action@v1
32+
with:
33+
branch: ${{ steps.git_info.outputs.current_branch }}
34+
workflow_id: conan.yml
35+
- name: Cancel scheduled build with no new commits
36+
uses: nrwl/last-successful-commit-action@v1
2437
if: |
25-
steps.new_commit_count.outputs.commit_count == '0' &&
26-
github.event_name == 'schedule'
38+
github.event_name == 'schedule' &&
39+
steps.git_info.outputs.current_commit == steps.last_successful_commit.outputs.commit_hash
2740
2841
build_macos:
2942
if: github.repository_owner == 'viamrobotics'

conanfile.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,15 @@ def set_version(self):
3232
self.version = re.search("set\(CMAKE_PROJECT_VERSION (.+)\)", content).group(1).strip()
3333

3434
def configure(self):
35-
# If we're building static then build the world as static, otherwise
36-
# stuff will probably break.
37-
# If you want your shared build to also build the world as shared, you
38-
# can invoke conan with -o "&:shared=False" -o "*:shared=False",
39-
# possibly with --build=missing or --build=cascade as desired,
40-
# but this is probably not necessary.
41-
if not self.options.shared:
42-
self.options["*"].shared = False
35+
if self.options.shared:
36+
# See https://github.com/conan-io/conan-center-index/issues/25107
37+
self.options["grpc"].secure = True
38+
39+
# From some experiments it seems that the shared-ness of these packages
40+
# should match that of the SDK recipe. Failure to do so can cause linker
41+
# errors while compiling, or static initialization errors at runtime for modules.
42+
for lib in ["grpc", "protobuf", "abseil"]:
43+
self.options[lib].shared = True
4344

4445
def requirements(self):
4546
self.requires('boost/[>=1.74.0]', transitive_headers=True)
@@ -49,8 +50,8 @@ def requirements(self):
4950
self.requires('grpc/[>=1.48.4]', transitive_headers=True)
5051
self.requires('protobuf/[>=3.17.1]', transitive_headers=True)
5152

52-
self.requires('xtensor/[>=0.24.3]', transitive_headers=True)
53-
self.requires('abseil/[>=20230125.3]')
53+
self.requires('xtensor/[>=0.24.3]')
54+
self.requires('abseil/[>=20230125.3]', transitive_libs=True)
5455

5556
def build_requirements(self):
5657
if self.options.offline_proto_generation:
@@ -83,13 +84,13 @@ def package(self):
8384

8485
def package_info(self):
8586
self.cpp_info.components["viam_rust_utils"].libs = ["viam_rust_utils"]
86-
87+
8788
self.cpp_info.components["viamsdk"].libs = ["viamsdk"]
8889

8990
for component in ["viamsdk", "viamapi"]:
9091
self.cpp_info.components[component].set_property("cmake_target_name", "viam-cpp-sdk::{}".format(component))
9192
self.cpp_info.components[component].set_property("pkg_config_name", "viam-cpp-sdk-lib{}".format(component))
92-
self.cpp_info.components[component].requires = ["grpc::grpc++", "protobuf::libprotobuf"]
93+
self.cpp_info.components[component].requires = ["grpc::grpc++"]
9394
if self.settings.os in ["Linux", "FreeBSD"]:
9495
self.cpp_info.components[component].system_libs = ["pthread"]
9596

@@ -114,11 +115,12 @@ def package_info(self):
114115
"viamapi",
115116
"boost::headers",
116117
"boost::log",
118+
"grpc::grpc++_reflection",
119+
"protobuf::libprotobuf",
117120
"xtensor::xtensor",
118121

119122
"viam_rust_utils",
120123
"abseil::absl_strings",
121-
"grpc::grpc++_reflection"
122124
])
123125

124126
self.cpp_info.components["viamsdk"].frameworks = ["Security"]

test_package/conanfile.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from conan.errors import ConanException
66
from conan.tools.cmake import CMake, cmake_layout
77
from conan.tools.build import can_run
8+
from conan.tools.env import VirtualRunEnv
89

910
class viamCppSdkTest(ConanFile):
1011
settings = "os", "compiler", "build_type", "arch"
@@ -25,11 +26,14 @@ def test(self):
2526
if can_run(self):
2627
sock = "fake-socket-path"
2728

28-
cmd = os.path.join(self.cpp.build.bindir, f"example_module {sock}")
29+
cmd = os.path.join(self.cpp.build.bindir, "example_module")
2930

3031
# the ConanFile run method is a wrapper around Popen, but it only returns the retcode.
3132
# A properly intialized module waits indefinitely on a signal, so we have to use Popen manually.
32-
proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, text=True)
33+
# Use VirtualRunEnv to perform the equivalent of passing env="conanrun" to self.run, so that
34+
# shared builds have a properly set LD_LIBRARY_PATH among other things.
35+
env = VirtualRunEnv(self).vars()
36+
proc = subprocess.Popen([cmd, sock], stdout=subprocess.PIPE, text=True, env=env)
3337

3438
out = None
3539

0 commit comments

Comments
 (0)