Skip to content

Commit 0f70a3c

Browse files
jimjingfmeum
andauthored
Add libmodbus (#3462)
Co-authored-by: Fabian Meumertzheim <[email protected]>
1 parent 1b45c47 commit 0f70a3c

File tree

7 files changed

+140
-0
lines changed

7 files changed

+140
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module(
2+
name = "libmodbus",
3+
version = "3.1.10",
4+
compatibility_level = 1,
5+
)
6+
bazel_dep(name = "bazel_skylib", version = "1.7.1")
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
diff --git a/BUILD b/BUILD
2+
new file mode 100644
3+
index 0000000..315d32e
4+
--- /dev/null
5+
+++ b/BUILD
6+
@@ -0,0 +1,60 @@
7+
+load("@bazel_skylib//rules:expand_template.bzl", "expand_template")
8+
+
9+
+cc_library(
10+
+ name = "modbus",
11+
+ srcs = glob(["src/*.c"]) + [
12+
+ ":generate_config_h",
13+
+ ":generate_modbus_version_h",
14+
+ ],
15+
+ hdrs = glob(["src/*.h"]),
16+
+ copts = ["-DHAVE_CONFIG_H"],
17+
+ includes = ["src"],
18+
+ include_prefix = "libmodbus",
19+
+ visibility = ["//visibility:public"],
20+
+)
21+
+
22+
+alias(
23+
+ name = "libmodbus",
24+
+ actual = ":modbus",
25+
+)
26+
+
27+
+cc_shared_library(
28+
+ name = "modbus_shared",
29+
+ additional_linker_inputs = [
30+
+ ":modbus-versionscript.lds",
31+
+ ],
32+
+ user_link_flags = [
33+
+ # Linker script to hide non-modbus symbols.
34+
+ "-Wl,--version-script",
35+
+ "$(location modbus-versionscript.lds)",
36+
+ ],
37+
+ visibility = ["//visibility:public"],
38+
+ deps = [
39+
+ ":modbus",
40+
+ ],
41+
+)
42+
+
43+
+expand_template(
44+
+ name = "generate_modbus_version_h",
45+
+ out = "src/modbus-version.h",
46+
+ substitutions = {
47+
+ "@LIBMODBUS_VERSION_MAJOR@": "3",
48+
+ "@LIBMODBUS_VERSION_MINOR@": "1",
49+
+ "@LIBMODBUS_VERSION_MICRO@": "10",
50+
+ "@LIBMODBUS_VERSION@": "3.1.10",
51+
+ },
52+
+ template = "src/modbus-version.h.in",
53+
+)
54+
+
55+
+genrule(
56+
+ name = "generate_config_h",
57+
+ outs = ["src/config.h"],
58+
+ cmd = """cat > $@ <<EOF
59+
+#define HAVE_DECL_TIOCM_RTS 1
60+
+#define HAVE_DECL_TIOCSRS485 1
61+
+#undef HAVE_ACCEPT4
62+
+#undef HAVE_GAI_STRERROR
63+
+#define HAVE_NETINET_IN_H 1
64+
+#define HAVE_NETINET_IP_H 1
65+
+""",
66+
+)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
diff --git a/modbus-versionscript.lds b/modbus-versionscript.lds
2+
new file mode 100644
3+
index 0000000..ea4858f
4+
--- /dev/null
5+
+++ b/modbus-versionscript.lds
6+
@@ -0,0 +1,5 @@
7+
+{
8+
+ global:
9+
+ modbus_*;
10+
+ local: *;
11+
+};
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
--- a/MODULE.bazel
2+
+++ a/MODULE.bazel
3+
@@ -0,0 +1,6 @@
4+
+module(
5+
+ name = "libmodbus",
6+
+ version = "3.1.10",
7+
+ compatibility_level = 1,
8+
+)
9+
+bazel_dep(name = "bazel_skylib", version = "1.7.1")
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
matrix:
2+
platform:
3+
- debian10
4+
- ubuntu2004
5+
bazel:
6+
- 8.x
7+
- 7.x
8+
tasks:
9+
verify_targets:
10+
name: Verify build targets
11+
platform: ${{ platform }}
12+
bazel: ${{ bazel }}
13+
build_targets:
14+
- '@libmodbus//:modbus'
15+
- '@libmodbus//:modbus_shared'
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"url": "https://github.com/stephane/libmodbus/releases/download/v3.1.10/libmodbus-3.1.10.tar.gz",
3+
"integrity": "sha256-iZvk4lq3/leZ1D+VZ1ENbwY9Lo9WE23XJrb9l2+bIlM=",
4+
"strip_prefix": "libmodbus-3.1.10",
5+
"patches": {
6+
"add_modbus_versionscript_dot_lds.patch": "sha256-O5Luywpd7kYnst/RMovKqi+ze1AGg/VCyFC7RN8HCvY=",
7+
"add_build_file.patch": "sha256-QJ61k+ie5LxcJ2ouQYRW2LDK2HaxFmEi94r5beBitFQ=",
8+
"module_dot_bazel.patch": "sha256-j4xOkLqnL9gHf0SvX4Z+OPIvh+Wywv1QNR0yK2xXkmw="
9+
},
10+
"patch_strip": 1
11+
}

modules/libmodbus/metadata.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"homepage": "www.libmodbus.org",
3+
"maintainers": [
4+
{
5+
"email": "[email protected]",
6+
"github": "mbeards",
7+
"name": "Michael Beardsworth"
8+
},
9+
{
10+
"email": "[email protected]",
11+
"github": "jimjing",
12+
"name": "Jim Jing"
13+
}
14+
],
15+
"repository": [
16+
"github:stephane/libmodbus"
17+
],
18+
"versions": [
19+
"3.1.10"
20+
],
21+
"yanked_versions": {}
22+
}

0 commit comments

Comments
 (0)