Skip to content

Commit 8ade24c

Browse files
authored
[wheel] Add rules to create a platform-independent wheel (#16)
Upgrade rules_python to 0.24.0. Remove spurous liblcm dependency from lcm-gen.
1 parent f9dab23 commit 8ade24c

File tree

7 files changed

+115
-35
lines changed

7 files changed

+115
-35
lines changed

README.md

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,32 @@ This repository contains a python application which translates data
44
streamed from the Optitrack Motive software (aka NatNet) into LCM
55
messages.
66

7-
To build:
7+
## To build and run locally:
88

9-
```bazel build //...```
9+
```
10+
bazel run //src:optitrack_client
11+
```
1012

11-
To run:
13+
## To build a wheel:
1214

13-
```bazel run //src:optitrack_client```
15+
```
16+
bazel build //wheel
17+
```
18+
19+
Then (within a virtual environment), install the wheel file:
20+
21+
```
22+
pip install bazel-bin/wheel/optitrack_driver-*-py3-none-any.whl
23+
```
24+
25+
Then (within the virtual environment), run the program as either:
26+
27+
```
28+
python -m optitrack.client
29+
```
30+
31+
or
32+
33+
```
34+
bin/optitrack_client
35+
```

WORKSPACE

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,9 @@ python_repository(name = "python")
7171

7272
http_archive(
7373
name = "rules_python",
74-
url = "https://github.com/bazelbuild/rules_python/releases/download/0.0.1/rules_python-0.0.1.tar.gz",
75-
sha256 = "aa96a691d3a8177f3215b14b0edc9641787abaaa30363a080165d06ab65e1161",
74+
url = "https://github.com/bazelbuild/rules_python/releases/download/0.24.0/rules_python-0.24.0.tar.gz",
75+
strip_prefix = "rules_python-0.24.0",
76+
sha256 = "0a8003b044294d7840ac7d9d73eef05d6ceb682d7516781a4ec62eeb34702578",
7677
)
7778

7879
load("@rules_python//python:repositories.bzl", "py_repositories")

install-optitrack.sh

Lines changed: 0 additions & 28 deletions
This file was deleted.

lcmtypes/BUILD.bazel

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,41 @@ LCM_SRCS = [
2020
"optitrack_skeleton_t.lcm",
2121
]
2222

23+
# Also provide the srcs in a package-specific subdir.
24+
[
25+
genrule(
26+
name = "_cp_" + x,
27+
srcs = [x],
28+
outs = ["optitrack/" + x],
29+
cmd = "cp $< $@",
30+
visibility = ["//visibility:private"],
31+
)
32+
for x in LCM_SRCS
33+
]
34+
35+
filegroup(
36+
name = "lcm_srcs_with_subdir",
37+
srcs = [
38+
":optitrack/" + x
39+
for x in LCM_SRCS
40+
],
41+
)
42+
2343
lcm_cc_library(
2444
name = "optitrack_lcmtypes",
2545
lcm_package = "optitrack",
2646
lcm_srcs = LCM_SRCS,
2747
linkstatic = 1,
2848
)
2949

50+
filegroup(
51+
name = "cxx_srcs",
52+
srcs = [
53+
":optitrack/" + x.replace(".lcm", ".hpp")
54+
for x in LCM_SRCS
55+
],
56+
)
57+
3058
lcm_py_library(
3159
name = "py_optitrack_lcmtypes",
3260
lcm_package = "optitrack",
@@ -38,3 +66,11 @@ lcm_java_library(
3866
lcm_package = "optitrack",
3967
lcm_srcs = LCM_SRCS,
4068
)
69+
70+
filegroup(
71+
name = "java_srcs",
72+
srcs = [
73+
":optitrack/" + x.replace(".lcm", ".java")
74+
for x in LCM_SRCS
75+
],
76+
)

tools/lcm.BUILD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ cc_binary(
132132
cc_binary(
133133
name = "lcm-gen",
134134
srcs = [
135+
"lcm/lcm_version.h",
135136
"lcmgen/emit_c.c",
136137
"lcmgen/emit_cpp.c",
137138
"lcmgen/emit_csharp.c",
@@ -150,7 +151,6 @@ cc_binary(
150151
copts = LCM_COPTS,
151152
includes = ["."],
152153
deps = [
153-
":lcm",
154154
"@glib",
155155
],
156156
)

version.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
VERSION = "0.0.20230714"

wheel/BUILD.bazel

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# -*- python -*-
2+
# This file contains rules for the Bazel build system; see https://bazel.build.
3+
4+
load("//:version.bzl", "VERSION")
5+
load("@rules_python//python:packaging.bzl", "py_wheel")
6+
7+
licenses(["notice"])
8+
9+
package(default_visibility = ["//visibility:private"])
10+
11+
genrule(
12+
name = "_cp_client",
13+
srcs = ["//src:optitrack_client.py"],
14+
outs = ["optitrack/client.py"],
15+
cmd = "cp $< $@",
16+
)
17+
18+
py_library(
19+
name = "client",
20+
srcs = [":optitrack/client.py"],
21+
)
22+
23+
py_wheel(
24+
name = "wheel",
25+
visibility = ["//visibility:public"],
26+
distribution = "optitrack_driver",
27+
version = VERSION,
28+
summary = "Translates data streamed from the Optitrack Motive software into LCM messages.",
29+
requires = [
30+
"lcm",
31+
],
32+
entry_points = {
33+
"console_scripts": [
34+
"optitrack_client = optitrack.client:main",
35+
],
36+
},
37+
deps = [
38+
":client",
39+
"//lcmtypes:cxx_srcs",
40+
"//lcmtypes:java_srcs",
41+
"//lcmtypes:lcm_srcs_with_subdir",
42+
"//lcmtypes:py_optitrack_lcmtypes",
43+
],
44+
strip_path_prefixes = [
45+
"lcmtypes/",
46+
"wheel/",
47+
],
48+
)

0 commit comments

Comments
 (0)