[llvm] [bazel][libc] Add htons function family and tests (PR #208201)
Pavel Labath via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 8 04:49:43 PDT 2026
https://github.com/labath created https://github.com/llvm/llvm-project/pull/208201
Add bazel build targets for the arpa/inet byte order functions (htonl, htons, ntohl, ntohs) and their corresponding unittests.
Assisted by Gemini.
>From 0561f3d9f1fefc260d57976c26955d3b5ebba887 Mon Sep 17 00:00:00 2001
From: Pavel Labath <pavel at labath.sk>
Date: Wed, 8 Jul 2026 11:42:05 +0000
Subject: [PATCH] [bazel][libc] Add htons function family and tests
Add bazel build targets for the arpa/inet byte order functions (htonl,
htons, ntohl, ntohs) and their corresponding unittests.
Assisted by Gemini.
---
.../llvm-project-overlay/libc/BUILD.bazel | 46 +++++++++++++++++
.../libc/test/src/arpa/inet/BUILD.bazel | 51 +++++++++++++++++++
2 files changed, 97 insertions(+)
create mode 100644 utils/bazel/llvm-project-overlay/libc/test/src/arpa/inet/BUILD.bazel
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",
+ ],
+)
More information about the llvm-commits
mailing list