Skip to content

Commit

Permalink
Add libmodbus (#3462)
Browse files Browse the repository at this point in the history
Co-authored-by: Fabian Meumertzheim <[email protected]>
  • Loading branch information
jimjing and fmeum authored Dec 21, 2024
1 parent 1b45c47 commit 0f70a3c
Show file tree
Hide file tree
Showing 7 changed files with 140 additions and 0 deletions.
6 changes: 6 additions & 0 deletions modules/libmodbus/3.1.10/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module(
name = "libmodbus",
version = "3.1.10",
compatibility_level = 1,
)
bazel_dep(name = "bazel_skylib", version = "1.7.1")
66 changes: 66 additions & 0 deletions modules/libmodbus/3.1.10/patches/add_build_file.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
diff --git a/BUILD b/BUILD
new file mode 100644
index 0000000..315d32e
--- /dev/null
+++ b/BUILD
@@ -0,0 +1,60 @@
+load("@bazel_skylib//rules:expand_template.bzl", "expand_template")
+
+cc_library(
+ name = "modbus",
+ srcs = glob(["src/*.c"]) + [
+ ":generate_config_h",
+ ":generate_modbus_version_h",
+ ],
+ hdrs = glob(["src/*.h"]),
+ copts = ["-DHAVE_CONFIG_H"],
+ includes = ["src"],
+ include_prefix = "libmodbus",
+ visibility = ["//visibility:public"],
+)
+
+alias(
+ name = "libmodbus",
+ actual = ":modbus",
+)
+
+cc_shared_library(
+ name = "modbus_shared",
+ additional_linker_inputs = [
+ ":modbus-versionscript.lds",
+ ],
+ user_link_flags = [
+ # Linker script to hide non-modbus symbols.
+ "-Wl,--version-script",
+ "$(location modbus-versionscript.lds)",
+ ],
+ visibility = ["//visibility:public"],
+ deps = [
+ ":modbus",
+ ],
+)
+
+expand_template(
+ name = "generate_modbus_version_h",
+ out = "src/modbus-version.h",
+ substitutions = {
+ "@LIBMODBUS_VERSION_MAJOR@": "3",
+ "@LIBMODBUS_VERSION_MINOR@": "1",
+ "@LIBMODBUS_VERSION_MICRO@": "10",
+ "@LIBMODBUS_VERSION@": "3.1.10",
+ },
+ template = "src/modbus-version.h.in",
+)
+
+genrule(
+ name = "generate_config_h",
+ outs = ["src/config.h"],
+ cmd = """cat > $@ <<EOF
+#define HAVE_DECL_TIOCM_RTS 1
+#define HAVE_DECL_TIOCSRS485 1
+#undef HAVE_ACCEPT4
+#undef HAVE_GAI_STRERROR
+#define HAVE_NETINET_IN_H 1
+#define HAVE_NETINET_IP_H 1
+""",
+)
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
diff --git a/modbus-versionscript.lds b/modbus-versionscript.lds
new file mode 100644
index 0000000..ea4858f
--- /dev/null
+++ b/modbus-versionscript.lds
@@ -0,0 +1,5 @@
+{
+ global:
+ modbus_*;
+ local: *;
+};
9 changes: 9 additions & 0 deletions modules/libmodbus/3.1.10/patches/module_dot_bazel.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
--- a/MODULE.bazel
+++ a/MODULE.bazel
@@ -0,0 +1,6 @@
+module(
+ name = "libmodbus",
+ version = "3.1.10",
+ compatibility_level = 1,
+)
+bazel_dep(name = "bazel_skylib", version = "1.7.1")
15 changes: 15 additions & 0 deletions modules/libmodbus/3.1.10/presubmit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
matrix:
platform:
- debian10
- ubuntu2004
bazel:
- 8.x
- 7.x
tasks:
verify_targets:
name: Verify build targets
platform: ${{ platform }}
bazel: ${{ bazel }}
build_targets:
- '@libmodbus//:modbus'
- '@libmodbus//:modbus_shared'
11 changes: 11 additions & 0 deletions modules/libmodbus/3.1.10/source.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"url": "https://github.com/stephane/libmodbus/releases/download/v3.1.10/libmodbus-3.1.10.tar.gz",
"integrity": "sha256-iZvk4lq3/leZ1D+VZ1ENbwY9Lo9WE23XJrb9l2+bIlM=",
"strip_prefix": "libmodbus-3.1.10",
"patches": {
"add_modbus_versionscript_dot_lds.patch": "sha256-O5Luywpd7kYnst/RMovKqi+ze1AGg/VCyFC7RN8HCvY=",
"add_build_file.patch": "sha256-QJ61k+ie5LxcJ2ouQYRW2LDK2HaxFmEi94r5beBitFQ=",
"module_dot_bazel.patch": "sha256-j4xOkLqnL9gHf0SvX4Z+OPIvh+Wywv1QNR0yK2xXkmw="
},
"patch_strip": 1
}
22 changes: 22 additions & 0 deletions modules/libmodbus/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"homepage": "www.libmodbus.org",
"maintainers": [
{
"email": "[email protected]",
"github": "mbeards",
"name": "Michael Beardsworth"
},
{
"email": "[email protected]",
"github": "jimjing",
"name": "Jim Jing"
}
],
"repository": [
"github:stephane/libmodbus"
],
"versions": [
"3.1.10"
],
"yanked_versions": {}
}

0 comments on commit 0f70a3c

Please sign in to comment.