[llvm] [bazel][libc] Add htons function family and tests (PR #208201)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 8 04:50:21 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libc
Author: Pavel Labath (labath)
<details>
<summary>Changes</summary>
Add bazel build targets for the arpa/inet byte order functions (htonl, htons, ntohl, ntohs) and their corresponding unittests.
Assisted by Gemini.
---
Full diff: https://github.com/llvm/llvm-project/pull/208201.diff
2 Files Affected:
- (modified) utils/bazel/llvm-project-overlay/libc/BUILD.bazel (+46)
- (added) utils/bazel/llvm-project-overlay/libc/test/src/arpa/inet/BUILD.bazel (+51)
``````````diff
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index 56ef8876c9e2d..812d37704efc9 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -3304,6 +3304,52 @@ libc_support_library(
],
)
+############################### arpa/inet targets ##############################
+
+libc_function(
+ name = "htonl",
+ srcs = ["src/arpa/inet/htonl.cpp"],
+ hdrs = ["src/arpa/inet/htonl.h"],
+ deps = [
+ ":__support_common",
+ ":__support_macros_config",
+ ":hdr_stdint_proxy",
+ ],
+)
+
+libc_function(
+ name = "htons",
+ srcs = ["src/arpa/inet/htons.cpp"],
+ hdrs = ["src/arpa/inet/htons.h"],
+ deps = [
+ ":__support_common",
+ ":__support_macros_config",
+ ":hdr_stdint_proxy",
+ ],
+)
+
+libc_function(
+ name = "ntohl",
+ srcs = ["src/arpa/inet/ntohl.cpp"],
+ hdrs = ["src/arpa/inet/ntohl.h"],
+ deps = [
+ ":__support_common",
+ ":__support_macros_config",
+ ":hdr_stdint_proxy",
+ ],
+)
+
+libc_function(
+ name = "ntohs",
+ srcs = ["src/arpa/inet/ntohs.cpp"],
+ hdrs = ["src/arpa/inet/ntohs.h"],
+ deps = [
+ ":__support_common",
+ ":__support_macros_config",
+ ":hdr_stdint_proxy",
+ ],
+)
+
################################# ctype targets ################################
libc_function(
diff --git a/utils/bazel/llvm-project-overlay/libc/test/src/arpa/inet/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/test/src/arpa/inet/BUILD.bazel
new file mode 100644
index 0000000000000..2f1bcd23ae0a7
--- /dev/null
+++ b/utils/bazel/llvm-project-overlay/libc/test/src/arpa/inet/BUILD.bazel
@@ -0,0 +1,51 @@
+# This file is licensed under the Apache License v2.0 with LLVM Exceptions.
+# See https://llvm.org/LICENSE.txt for license information.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+# Tests for LLVM libc arpa/inet.h functions.
+
+load("//libc/test:libc_test_rules.bzl", "libc_test")
+
+package(default_visibility = ["//visibility:public"])
+
+licenses(["notice"])
+
+libc_test(
+ name = "htonl_test",
+ srcs = ["htonl_test.cpp"],
+ deps = [
+ "//libc:__support_common",
+ "//libc:htonl",
+ "//libc:ntohl",
+ ],
+)
+
+libc_test(
+ name = "htons_test",
+ srcs = ["htons_test.cpp"],
+ deps = [
+ "//libc:__support_common",
+ "//libc:htons",
+ "//libc:ntohs",
+ ],
+)
+
+libc_test(
+ name = "ntohl_test",
+ srcs = ["ntohl_test.cpp"],
+ deps = [
+ "//libc:__support_common",
+ "//libc:htonl",
+ "//libc:ntohl",
+ ],
+)
+
+libc_test(
+ name = "ntohs_test",
+ srcs = ["ntohs_test.cpp"],
+ deps = [
+ "//libc:__support_common",
+ "//libc:htons",
+ "//libc:ntohs",
+ ],
+)
``````````
</details>
https://github.com/llvm/llvm-project/pull/208201
More information about the llvm-commits
mailing list