pkgsrc-WIP-changes archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

wip/bazel: import bazel-6.4.0



Module Name:	pkgsrc-wip
Committed By:	Ryo ONODERA <ryoon%NetBSD.org@localhost>
Pushed By:	ryoon
Date:		Fri Dec 1 00:04:03 2023 +0900
Changeset:	52e4c0b7c19ead2f69502684930aef2c7c87fc8a

Added Files:
	bazel/DESCR
	bazel/Makefile
	bazel/PLIST
	bazel/distinfo
	bazel/patches/patch-distdir__deps.bzl
	bazel/patches/patch-scripts_bootstrap_buildenv.sh
	bazel/patches/patch-scripts_packages_BUILD
	bazel/patches/patch-scripts_packages_template__bin.sh
	bazel/patches/patch-src_BUILD
	bazel/patches/patch-src_conditions_BUILD
	bazel/patches/patch-src_conditions_BUILD.tools
	bazel/patches/patch-src_main_cpp_BUILD
	bazel/patches/patch-src_main_cpp_blaze__util__bsd.cc
	bazel/patches/patch-src_main_java_com_google_devtools_build_lib_analysis_ShellConfiguration.java
	bazel/patches/patch-src_main_java_com_google_devtools_build_lib_analysis_config_AutoCpuConverter.java
	bazel/patches/patch-src_main_java_com_google_devtools_build_lib_bazel_repository_LocalConfigPlatformFunction.java
	bazel/patches/patch-src_main_java_com_google_devtools_build_lib_bazel_rules_BazelRuleClassProvider.java
	bazel/patches/patch-src_main_java_com_google_devtools_build_lib_jni_JniLoader.java
	bazel/patches/patch-src_main_java_com_google_devtools_build_lib_runtime_CommonCommandOptions.java
	bazel/patches/patch-src_main_java_com_google_devtools_build_lib_runtime_ConfigExpander.java
	bazel/patches/patch-src_main_java_com_google_devtools_build_lib_util_OS.java
	bazel/patches/patch-src_main_native_BUILD
	bazel/patches/patch-src_main_native_unix__jni.h
	bazel/patches/patch-src_main_native_unix__jni__bsd.cc
	bazel/patches/patch-src_main_tools_BUILD
	bazel/patches/patch-src_main_tools_process-tools-darwin.cc
	bazel/patches/patch-src_test_java_com_google_devtools_build_lib_bazel_repository_LocalConfigPlatformFunctionTest.java
	bazel/patches/patch-src_test_java_com_google_devtools_build_lib_bazel_rules_BazelRuleClassProviderTest.java
	bazel/patches/patch-src_test_java_com_google_devtools_build_lib_packages_util_MockPlatformSupport.java
	bazel/patches/patch-src_test_java_com_google_devtools_build_lib_platform_SleepPreventionModuleTest.java
	bazel/patches/patch-src_test_java_com_google_devtools_build_lib_runtime_BlazeOptionHandlerTest.java
	bazel/patches/patch-src_test_java_com_google_devtools_build_lib_runtime_commands_CleanCommandRecommendsAsyncTest.java
	bazel/patches/patch-src_test_shell_bazel_remote_remote__execution__test.sh
	bazel/patches/patch-src_test_shell_bazel_unicode__filenames__test.sh
	bazel/patches/patch-src_test_shell_shell__utils.sh
	bazel/patches/patch-src_tools_singlejar_BUILD
	bazel/patches/patch-src_tools_singlejar_diag.h
	bazel/patches/patch-src_tools_singlejar_mapped__file__posix.inc
	bazel/patches/patch-src_tools_singlejar_port.h
	bazel/patches/patch-src_tools_singlejar_zip__headers.h
	bazel/patches/patch-third__party_BUILD
	bazel/patches/patch-third__party_abseil-cpp_netbsd-sunos.patch
	bazel/patches/patch-third__party_grpc_netbsd-config.patch
	bazel/patches/patch-third__party_zstd-jni_zstd-jni.BUILD
	bazel/patches/patch-tools_cpp_BUILD.static.bsd
	bazel/patches/patch-tools_cpp_bsd__cc__toolchain__config.bzl
	bazel/patches/patch-tools_cpp_cc__configure.bzl
	bazel/patches/patch-tools_cpp_lib__cc__configure.bzl
	bazel/patches/patch-tools_cpp_unix__cc__configure.bzl
	bazel/patches/patch-tools_jdk_BUILD.java__tools
	bazel/patches/patch-tools_jdk_BUILD.tools
	bazel/patches/patch-tools_jdk_jdk__build__file.bzl
	bazel/patches/patch-tools_platforms_BUILD
	bazel/patches/patch-tools_platforms_BUILD.tools

Log Message:
wip/bazel: import bazel-6.4.0

{Fast, Correct} - Choose two

Build and test software of any size, quickly and reliably.

* Speed up your builds and tests:
  Bazel rebuilds only what is necessary.
  With advanced local and distributed caching, optimized dependency analysis
  and parallel execution, you get fast and incremental builds.

* One tool, multiple languages:
  Build and test Java, C++, Android, iOS, Go,
  and a wide variety of other language platforms.
  Bazel runs on Windows, macOS, and Linux.

* Scalable:
  Bazel helps you scale your organization, codebase, and
  continuous integration solution. It handles codebases of any size,
  in multiple repositories or a huge monorepo.

* Extensible to your needs:
  Easily add support for new languages and platforms with Bazel's familiar
  extension language. Share and re-use language rules written
  by the growing Bazel community.

To see a diff of this commit:
https://wip.pkgsrc.org/cgi-bin/gitweb.cgi?p=pkgsrc-wip.git;a=commitdiff;h=52e4c0b7c19ead2f69502684930aef2c7c87fc8a

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

diffstat:
 bazel/DESCR                                        |  23 +
 bazel/Makefile                                     |  71 +++
 bazel/PLIST                                        |   2 +
 bazel/distinfo                                     |  55 +++
 bazel/patches/patch-distdir__deps.bzl              |  22 +
 bazel/patches/patch-scripts_bootstrap_buildenv.sh  |  16 +
 bazel/patches/patch-scripts_packages_BUILD         |  12 +
 .../patch-scripts_packages_template__bin.sh        |  15 +
 bazel/patches/patch-src_BUILD                      |  20 +
 bazel/patches/patch-src_conditions_BUILD           |  17 +
 bazel/patches/patch-src_conditions_BUILD.tools     |  17 +
 bazel/patches/patch-src_main_cpp_BUILD             |  33 ++
 .../patches/patch-src_main_cpp_blaze__util__bsd.cc |  41 ++
 ...ools_build_lib_analysis_ShellConfiguration.java |  16 +
 ...build_lib_analysis_config_AutoCpuConverter.java |  22 +
 ...zel_repository_LocalConfigPlatformFunction.java |  13 +
 ...ild_lib_bazel_rules_BazelRuleClassProvider.java |  12 +
 ...om_google_devtools_build_lib_jni_JniLoader.java |  12 +
 ...ols_build_lib_runtime_CommonCommandOptions.java |  13 +
 ..._devtools_build_lib_runtime_ConfigExpander.java |  13 +
 ...java_com_google_devtools_build_lib_util_OS.java |  19 +
 bazel/patches/patch-src_main_native_BUILD          |  20 +
 bazel/patches/patch-src_main_native_unix__jni.h    |  13 +
 .../patch-src_main_native_unix__jni__bsd.cc        |  13 +
 bazel/patches/patch-src_main_tools_BUILD           |  44 ++
 .../patch-src_main_tools_process-tools-darwin.cc   |  24 +
 ...repository_LocalConfigPlatformFunctionTest.java |  12 +
 ...lib_bazel_rules_BazelRuleClassProviderTest.java |  22 +
 ...uild_lib_packages_util_MockPlatformSupport.java |  15 +
 ...ild_lib_platform_SleepPreventionModuleTest.java |  12 +
 ...s_build_lib_runtime_BlazeOptionHandlerTest.java |  32 ++
 ...e_commands_CleanCommandRecommendsAsyncTest.java |  20 +
 ...t_shell_bazel_remote_remote__execution__test.sh |  22 +
 ...rc_test_shell_bazel_unicode__filenames__test.sh |  13 +
 bazel/patches/patch-src_test_shell_shell__utils.sh |  13 +
 bazel/patches/patch-src_tools_singlejar_BUILD      |  20 +
 bazel/patches/patch-src_tools_singlejar_diag.h     |  13 +
 ...tch-src_tools_singlejar_mapped__file__posix.inc |  13 +
 bazel/patches/patch-src_tools_singlejar_port.h     |  13 +
 .../patch-src_tools_singlejar_zip__headers.h       |  13 +
 bazel/patches/patch-third__party_BUILD             |  24 +
 ...atch-third__party_abseil-cpp_netbsd-sunos.patch |  90 ++++
 .../patch-third__party_grpc_netbsd-config.patch    | 546 +++++++++++++++++++++
 .../patch-third__party_zstd-jni_zstd-jni.BUILD     |  12 +
 bazel/patches/patch-tools_cpp_BUILD.static.bsd     |  57 +++
 .../patch-tools_cpp_bsd__cc__toolchain__config.bzl |  49 ++
 bazel/patches/patch-tools_cpp_cc__configure.bzl    |  13 +
 .../patches/patch-tools_cpp_lib__cc__configure.bzl |  13 +
 .../patch-tools_cpp_unix__cc__configure.bzl        |  13 +
 bazel/patches/patch-tools_jdk_BUILD.java__tools    |  33 ++
 bazel/patches/patch-tools_jdk_BUILD.tools          |  32 ++
 bazel/patches/patch-tools_jdk_jdk__build__file.bzl |  17 +
 bazel/patches/patch-tools_platforms_BUILD          |  32 ++
 bazel/patches/patch-tools_platforms_BUILD.tools    |  32 ++
 54 files changed, 1774 insertions(+)

diffs:
diff --git a/bazel/DESCR b/bazel/DESCR
new file mode 100644
index 0000000000..d5069bea5e
--- /dev/null
+++ b/bazel/DESCR
@@ -0,0 +1,23 @@
+{Fast, Correct} - Choose two
+
+Build and test software of any size, quickly and reliably.
+
+* Speed up your builds and tests:
+  Bazel rebuilds only what is necessary.
+  With advanced local and distributed caching, optimized dependency analysis
+  and parallel execution, you get fast and incremental builds.
+
+* One tool, multiple languages:
+  Build and test Java, C++, Android, iOS, Go,
+  and a wide variety of other language platforms.
+  Bazel runs on Windows, macOS, and Linux.
+
+* Scalable:
+  Bazel helps you scale your organization, codebase, and
+  continuous integration solution. It handles codebases of any size,
+  in multiple repositories or a huge monorepo.
+
+* Extensible to your needs:
+  Easily add support for new languages and platforms with Bazel's familiar
+  extension language. Share and re-use language rules written
+  by the growing Bazel community.
diff --git a/bazel/Makefile b/bazel/Makefile
new file mode 100644
index 0000000000..af61f475b2
--- /dev/null
+++ b/bazel/Makefile
@@ -0,0 +1,71 @@
+# $NetBSD$
+
+# Java project does not work as follows:
+# Error: could not find libjava.so
+# Error: Could not find Java SE Runtime Environment.
+
+# To bootstrap Bezel, apply all patches and run as do-build target
+# defines under Linux.
+
+.if UPSTREAM
+DISTNAME=	bazel-6.4.0-dist
+PKGNAME=	${DISTNAME:S/-dist//}
+MASTER_SITES=	${MASTER_SITE_GITHUB:=bazelbuild/}
+GITHUB_PROJECT=	bazel
+GITHUB_RELEASE= ${PKGVERSION_NOREV}
+EXTRACT_SUFX=	.zip
+.else
+DISTNAME=	bazel-6.4.0-dist-netbsd
+PKGNAME=	${DISTNAME:S/-dist-netbsd//}
+#MASTER_SITES=	${MASTER_SITE_LOCAL}
+MASTER_SITES=	https://www.ryoon.net/~ryoon/bazel/20231130/
+.endif
+CATEGORIES=	devel
+
+MAINTAINER=	ryoon%NetBSD.org@localhost
+HOMEPAGE=	https://bazel.build/
+COMMENT=	Fast and correct build automation tool
+LICENSE=	apache-2.0
+
+BROKEN_ON_PLATFORM=	${LP32PLATFORMS}
+
+WRKSRC=		${WRKDIR}
+USE_TOOLS+=	bash pkg-config unzip zip
+USE_LANGUAGES=	c c++
+
+CHECK_PIE_SUPPORTED=	no
+
+USE_JAVA=		yes
+USE_JAVA2=		11
+PKG_JVMS_ACCEPTED=	openjdk11
+
+REPLACE_BASH+=	*.sh
+REPLACE_BASH+=	scripts/*.sh
+REPLACE_BASH+=	tools/*.sh
+REPLACE_BASH+=	tools/*/*.sh
+
+MAKE_ENV+=	EXTRA_BAZEL_ARGS="--tool_java_runtime_version=local_jdk"
+
+INSTALLATION_DIRS+=	bin
+
+do-patch:
+	# Do not perform patching. The tarball includes all patches.
+
+pre-configure:
+	${FIND} ${WRKSRC} | ${GREP} '\.orig$$' | xargs ${RM}
+	# TODO: Honor environment variables
+	${RM} -r ${WRKDIR}/.cwrapper
+
+do-build:
+	cd ${WRKSRC} \
+	&& env ${MAKE_ENV} \
+		${BASH} ./compile.sh
+
+do-install:
+	# Do not strip bazel binary. It includes .zip archive.
+	${INSTALL_SCRIPT} ${WRKSRC}/output/bazel \
+		${DESTDIR}${PREFIX}/bin
+
+.include "../../lang/python/tool.mk"
+.include "../../mk/java-vm.mk"
+.include "../../mk/bsd.pkg.mk"
diff --git a/bazel/PLIST b/bazel/PLIST
new file mode 100644
index 0000000000..d8c572417e
--- /dev/null
+++ b/bazel/PLIST
@@ -0,0 +1,2 @@
+@comment $NetBSD$
+bin/bazel
diff --git a/bazel/distinfo b/bazel/distinfo
new file mode 100644
index 0000000000..16af22f795
--- /dev/null
+++ b/bazel/distinfo
@@ -0,0 +1,55 @@
+$NetBSD$
+
+BLAKE2s (bazel-6.4.0-dist-netbsd.tar.gz) = 7ea455aa75176cea36f261671b827b433d0ffb15acb653740d867757c213e5b2
+SHA512 (bazel-6.4.0-dist-netbsd.tar.gz) = 71b2fe9ebd635b4d7fd69a50e4ef8897154016e3e3d400c2bf0eda0e1bc56006d75518de971760fd8c35576832cd33a0d6e62b89d052d872e005280d72a9464d
+Size (bazel-6.4.0-dist-netbsd.tar.gz) = 198661276 bytes
+SHA1 (patch-distdir__deps.bzl) = 83dead7d5c7374ae7ada4feec5ec3bbd18d9112b
+SHA1 (patch-scripts_bootstrap_buildenv.sh) = 7590cf62b1b7abe722addeddd3d4f0595ebc2a1f
+SHA1 (patch-scripts_packages_BUILD) = 9cbd73caefe9f7b1b23cbbedf3657ee849d4dfdc
+SHA1 (patch-scripts_packages_template__bin.sh) = 8e5c504041bd7a74c3f83177c58844428fc03c07
+SHA1 (patch-src_BUILD) = cd8858313bec19f56c148944eea0962c9ef83d98
+SHA1 (patch-src_conditions_BUILD) = 5e099200f294e5905a09d323d95161784586e91c
+SHA1 (patch-src_conditions_BUILD.tools) = aec0d6cb07d19229a0e29827b4716c35816c4a7e
+SHA1 (patch-src_main_cpp_BUILD) = f14c549105eeba47593842569822fb2f65a01479
+SHA1 (patch-src_main_cpp_blaze__util__bsd.cc) = dda2e930455ff85a207779f14ec8ee677e99adc7
+SHA1 (patch-src_main_java_com_google_devtools_build_lib_analysis_ShellConfiguration.java) = 2030b61056c3919b68dfa22a133e2c66f14ad3c7
+SHA1 (patch-src_main_java_com_google_devtools_build_lib_analysis_config_AutoCpuConverter.java) = 2e4158f0c25afab27abf4316f0580ba99cbbd1eb
+SHA1 (patch-src_main_java_com_google_devtools_build_lib_bazel_repository_LocalConfigPlatformFunction.java) = fb8e2c15b99af685daffa23577da09223fc8cd4b
+SHA1 (patch-src_main_java_com_google_devtools_build_lib_bazel_rules_BazelRuleClassProvider.java) = 1cd3916bd1d46a4a3f138abced90d935d5efe0fe
+SHA1 (patch-src_main_java_com_google_devtools_build_lib_jni_JniLoader.java) = 67bd0f3c49b4578788f7915a66e289f9eff811e6
+SHA1 (patch-src_main_java_com_google_devtools_build_lib_runtime_CommonCommandOptions.java) = f4a3ee5d9a2cbb59f0523c8eb4b040e9b1f5b67b
+SHA1 (patch-src_main_java_com_google_devtools_build_lib_runtime_ConfigExpander.java) = 88d0fa5f4ba3ce24f4ff5ccdae8733928ce7ae31
+SHA1 (patch-src_main_java_com_google_devtools_build_lib_util_OS.java) = c6a3cbbfad7ed93c98b5c3ff1a7180896e9bec47
+SHA1 (patch-src_main_native_BUILD) = 6c836b178c62086912f5d04f3033ac3ddd6e54fc
+SHA1 (patch-src_main_native_unix__jni.h) = c400b1c16e24bc4aa6d3bed9b3deab06b070bd59
+SHA1 (patch-src_main_native_unix__jni__bsd.cc) = 609401cf5a5d7c1aa51857325975d725c86604f2
+SHA1 (patch-src_main_tools_BUILD) = b3367d262baeaf11270adf2d07bca8a454c34d18
+SHA1 (patch-src_main_tools_process-tools-darwin.cc) = 1dbd651db7168d1d271b35360563a093c4b9c93c
+SHA1 (patch-src_test_java_com_google_devtools_build_lib_bazel_repository_LocalConfigPlatformFunctionTest.java) = 7864beee5b5578306a5658dda2fb208e3bd96b88
+SHA1 (patch-src_test_java_com_google_devtools_build_lib_bazel_rules_BazelRuleClassProviderTest.java) = 32f502ee4a7e8544d756549eb731e4729295f116
+SHA1 (patch-src_test_java_com_google_devtools_build_lib_packages_util_MockPlatformSupport.java) = 2e5f30990b416e38fdce6880dc4d62a9efe43bd7
+SHA1 (patch-src_test_java_com_google_devtools_build_lib_platform_SleepPreventionModuleTest.java) = c319becdb97dc2f943f4efab4dee5f2111335249
+SHA1 (patch-src_test_java_com_google_devtools_build_lib_runtime_BlazeOptionHandlerTest.java) = 0ba888236aa71b178b5c4ad25d8467699fdaf0e8
+SHA1 (patch-src_test_java_com_google_devtools_build_lib_runtime_commands_CleanCommandRecommendsAsyncTest.java) = 2277335022ef5f48671f41fab58c791bdd752fe3
+SHA1 (patch-src_test_shell_bazel_remote_remote__execution__test.sh) = c397b0bff97b6e13017e0b87c049e741860aab1d
+SHA1 (patch-src_test_shell_bazel_unicode__filenames__test.sh) = 72e74231ccec777abc78afdd7e851be72364753b
+SHA1 (patch-src_test_shell_shell__utils.sh) = c8de670f9f210adbbf7963bea61d98ac7fde8dde
+SHA1 (patch-src_tools_singlejar_BUILD) = ea7fa7f12c4e5b209f556cbbd2bfa35a74bc7c50
+SHA1 (patch-src_tools_singlejar_diag.h) = a008b77283d31a63ee13edc9259cd8eeaed5498c
+SHA1 (patch-src_tools_singlejar_mapped__file__posix.inc) = fc9d9407d173ad95984cf53ac8bb44e23c37a9f0
+SHA1 (patch-src_tools_singlejar_port.h) = ef1e7ad8eb101aa76e794f95f6b4eb20155146d8
+SHA1 (patch-src_tools_singlejar_zip__headers.h) = 0f2f98f4677118214c7b93cbfeb9399c3d0939b1
+SHA1 (patch-third__party_BUILD) = 05d665afc9d1697867102b3737467241f4b2b610
+SHA1 (patch-third__party_abseil-cpp_netbsd-sunos.patch) = c9ff33d2c331312736db8f26c47e8e0b6d7a671f
+SHA1 (patch-third__party_grpc_netbsd-config.patch) = ea14e800a118a3541356c00df5d8edb1aed309fa
+SHA1 (patch-third__party_zstd-jni_zstd-jni.BUILD) = 338d636638b429da3f8a695cc15010174651dd23
+SHA1 (patch-tools_cpp_BUILD.static.bsd) = af9e8cf9f2f069bc4264f4ab3e57aa1e8686946a
+SHA1 (patch-tools_cpp_bsd__cc__toolchain__config.bzl) = 369dbfe8b29749cb8aa7dff66dd6cadc8a7190b9
+SHA1 (patch-tools_cpp_cc__configure.bzl) = 24cd5bb7b7a09d12853a7b19a8c41b875a51a30f
+SHA1 (patch-tools_cpp_lib__cc__configure.bzl) = 02a5c867e61f7f59fa2fd61e70548c25448aa366
+SHA1 (patch-tools_cpp_unix__cc__configure.bzl) = a5d181c89fd032e02032d27d0189a8db6a936de4
+SHA1 (patch-tools_jdk_BUILD.java__tools) = 5b7e1e2c0db74afe7fd8dfbd71cd9c218943c9af
+SHA1 (patch-tools_jdk_BUILD.tools) = 6d885bb5735ece725b8aaa89cdea7ccd3e52f4fa
+SHA1 (patch-tools_jdk_jdk__build__file.bzl) = ba8efebeca29d66ab84915b94fd3edfb69319880
+SHA1 (patch-tools_platforms_BUILD) = 11fe48b55a3211b92a80e7e914ee3c4e9880444a
+SHA1 (patch-tools_platforms_BUILD.tools) = 07d198d96000982bce176ab24a45c55270d7d4e6
diff --git a/bazel/patches/patch-distdir__deps.bzl b/bazel/patches/patch-distdir__deps.bzl
new file mode 100644
index 0000000000..192078efcd
--- /dev/null
+++ b/bazel/patches/patch-distdir__deps.bzl
@@ -0,0 +1,22 @@
+$NetBSD$
+
+--- distdir_deps.bzl.orig	1979-12-31 15:00:00.000000000 +0000
++++ distdir_deps.bzl
+@@ -123,6 +123,7 @@ DIST_DEPS = {
+         "patches": [
+             "//third_party/grpc:grpc_1.47.0.patch",
+             "//third_party/grpc:grpc_1.47.0.win_arm64.patch",
++            "//third_party/grpc:netbsd-config.patch",
+         ],
+         "used_in": [
+             "additional_distfiles",
+@@ -240,6 +241,9 @@ DIST_DEPS = {
+             "test_WORKSPACE_files",
+         ],
+         "strip_prefix": "abseil-cpp-20211102.0",
++        "patches": [
++            "//third_party:abseil-cpp/netbsd-sunos.patch",
++        ],
+     },
+     "zstd-jni": {
+         "archive": "v1.5.2-3.zip",
diff --git a/bazel/patches/patch-scripts_bootstrap_buildenv.sh b/bazel/patches/patch-scripts_bootstrap_buildenv.sh
new file mode 100644
index 0000000000..a60fa8775f
--- /dev/null
+++ b/bazel/patches/patch-scripts_bootstrap_buildenv.sh
@@ -0,0 +1,16 @@
+$NetBSD$
+
+--- scripts/bootstrap/buildenv.sh.orig	2023-11-28 16:39:24.563015783 +0000
++++ scripts/bootstrap/buildenv.sh
+@@ -93,6 +93,11 @@ freebsd)
+   JAVA_HOME="${JAVA_HOME:-/usr/local/openjdk11}"
+   ;;
+ 
++netbsd)
++  # JAVA_HOME must point to a Java installation.
++  JAVA_HOME="${JAVA_HOME:-/usr/pkg/java/openjdk11}"
++  ;;
++
+ openbsd)
+   # JAVA_HOME must point to a Java installation.
+   JAVA_HOME="${JAVA_HOME:-/usr/local/jdk-11}"
diff --git a/bazel/patches/patch-scripts_packages_BUILD b/bazel/patches/patch-scripts_packages_BUILD
new file mode 100644
index 0000000000..33d112f369
--- /dev/null
+++ b/bazel/patches/patch-scripts_packages_BUILD
@@ -0,0 +1,12 @@
+$NetBSD$
+
+--- scripts/packages/BUILD.orig	2023-11-28 16:36:12.390418705 +0000
++++ scripts/packages/BUILD
+@@ -23,6 +23,7 @@ filegroup(
+             ":zip-bazel-exe_nojdk",
+         ],
+         "//src/conditions:freebsd": [],
++        "//src/conditions:netbsd": [],
+         "//src/conditions:openbsd": [],
+         "//src/conditions:darwin": [
+             ":with-jdk/install.sh",
diff --git a/bazel/patches/patch-scripts_packages_template__bin.sh b/bazel/patches/patch-scripts_packages_template__bin.sh
new file mode 100644
index 0000000000..39f0c6b038
--- /dev/null
+++ b/bazel/patches/patch-scripts_packages_template__bin.sh
@@ -0,0 +1,15 @@
+$NetBSD$
+
+--- scripts/packages/template_bin.sh.orig	2023-11-28 16:39:59.898140894 +0000
++++ scripts/packages/template_bin.sh
+@@ -115,6 +115,10 @@ if [ -z "${JAVA_HOME-}" ]; then
+       JAVA_HOME="/usr/local/openjdk8"
+       BASHRC="~/.bashrc"
+       ;;
++    netbsd)
++      JAVA_HOME="/usr/pkg/java/openjdk8"
++      BASHRC="~/.bashrc"
++      ;;
+     openbsd)
+       JAVA_HOME="/usr/local/jdk-1.8.0"
+       BASHRC="~/.bashrc"
diff --git a/bazel/patches/patch-src_BUILD b/bazel/patches/patch-src_BUILD
new file mode 100644
index 0000000000..d787b2eb38
--- /dev/null
+++ b/bazel/patches/patch-src_BUILD
@@ -0,0 +1,20 @@
+$NetBSD$
+
+--- src/BUILD.orig	2023-11-29 11:57:08.056842619 +0000
++++ src/BUILD
+@@ -34,6 +34,7 @@ md5_cmd = "set -e -o pipefail && %s $(SR
+     cmd = select({
+         "//src/conditions:darwin": md5_cmd % ("/sbin/md5", "/sbin/md5", "head -c 32"),
+         "//src/conditions:freebsd": md5_cmd % ("/sbin/md5", "/sbin/md5", "head -c 32"),
++        "//src/conditions:netbsd": md5_cmd % ("/usr/bin/md5", "/usr/bin/md5", "head -c 32"),
+         # We avoid using the `head` tool's `-c` option, since it does not exist
+         # on OpenBSD.
+         "//src/conditions:openbsd": md5_cmd % ("/bin/md5", "/bin/md5", "dd bs=32 count=1"),
+@@ -349,6 +350,7 @@ genrule(
+     srcs = ["package-bazel.sh"],
+     outs = ["package-bazel-on-host-platform.sh"],
+     cmd = select({
++        "//src/conditions:netbsd": "cat $(SRCS) | sed -e 's@#!/bin/bash@#!/usr/pkg/bin/bash@' > $@",
+         "//src/conditions:openbsd": "cat $(SRCS) | sed -e 's@#!/bin/bash@#!/usr/local/bin/bash@' > $@",
+         "//conditions:default": "cp $(SRCS) $@",
+     }),
diff --git a/bazel/patches/patch-src_conditions_BUILD b/bazel/patches/patch-src_conditions_BUILD
new file mode 100644
index 0000000000..2f46a37b85
--- /dev/null
+++ b/bazel/patches/patch-src_conditions_BUILD
@@ -0,0 +1,17 @@
+$NetBSD$
+
+--- src/conditions/BUILD.orig	2023-11-29 00:17:37.410068236 +0000
++++ src/conditions/BUILD
+@@ -160,6 +160,12 @@ config_setting(
+ )
+ 
+ config_setting(
++    name = "netbsd",
++    constraint_values = ["@platforms//os:netbsd"],
++    visibility = ["//visibility:public"],
++)
++
++config_setting(
+     name = "openbsd",
+     constraint_values = ["@platforms//os:openbsd"],
+     visibility = ["//visibility:public"],
diff --git a/bazel/patches/patch-src_conditions_BUILD.tools b/bazel/patches/patch-src_conditions_BUILD.tools
new file mode 100644
index 0000000000..db2bf94a64
--- /dev/null
+++ b/bazel/patches/patch-src_conditions_BUILD.tools
@@ -0,0 +1,17 @@
+$NetBSD$
+
+--- src/conditions/BUILD.tools.orig	2023-11-28 16:36:42.721951524 +0000
++++ src/conditions/BUILD.tools
+@@ -7,6 +7,12 @@ config_setting(
+ )
+ 
+ config_setting(
++    name = "netbsd",
++    constraint_values = ["@platforms//os:netbsd"],
++    visibility = ["//visibility:public"],
++)
++
++config_setting(
+     name = "openbsd",
+     constraint_values = ["@platforms//os:openbsd"],
+     visibility = ["//visibility:public"],
diff --git a/bazel/patches/patch-src_main_cpp_BUILD b/bazel/patches/patch-src_main_cpp_BUILD
new file mode 100644
index 0000000000..94ed322ef2
--- /dev/null
+++ b/bazel/patches/patch-src_main_cpp_BUILD
@@ -0,0 +1,33 @@
+$NetBSD$
+
+--- src/main/cpp/BUILD.orig	2023-11-28 16:40:47.721393251 +0000
++++ src/main/cpp/BUILD
+@@ -26,6 +26,10 @@ cc_library(
+             "blaze_util_bsd.cc",
+             "blaze_util_posix.cc",
+         ],
++        "//src/conditions:netbsd": [
++            "blaze_util_bsd.cc",
++            "blaze_util_posix.cc",
++        ],
+         "//src/conditions:openbsd": [
+             "blaze_util_bsd.cc",
+             "blaze_util_posix.cc",
+@@ -49,6 +53,8 @@ cc_library(
+         ],
+         "//src/conditions:freebsd": [
+         ],
++        "//src/conditions:netbsd": [
++        ],
+         "//src/conditions:openbsd": [
+         ],
+         "//src/conditions:windows": WIN_LINK_OPTS,
+@@ -110,6 +116,8 @@ cc_binary(
+             "-lprocstat",
+             "-lm",
+         ],
++        "//src/conditions:netbsd": [
++        ],
+         "//src/conditions:openbsd": [
+         ],
+         "//src/conditions:windows": [
diff --git a/bazel/patches/patch-src_main_cpp_blaze__util__bsd.cc b/bazel/patches/patch-src_main_cpp_blaze__util__bsd.cc
new file mode 100644
index 0000000000..47ba827f84
--- /dev/null
+++ b/bazel/patches/patch-src_main_cpp_blaze__util__bsd.cc
@@ -0,0 +1,41 @@
+$NetBSD$
+
+--- src/main/cpp/blaze_util_bsd.cc.orig	2023-11-29 06:03:37.228876616 +0000
++++ src/main/cpp/blaze_util_bsd.cc
+@@ -15,6 +15,8 @@
+ #if defined(__FreeBSD__)
+ # define HAVE_PROCSTAT
+ # define STANDARD_JAVABASE "/usr/local/openjdk8"
++#elif defined(__NetBSD__)
++# define STANDARD_JAVABASE "/usr/pkg/java/openjdk17"
+ #elif defined(__OpenBSD__)
+ # define STANDARD_JAVABASE "/usr/local/jdk-17"
+ #else
+@@ -36,6 +38,7 @@
+ #include <sys/param.h>
+ #include <sys/queue.h>
+ #include <sys/socket.h>
++#include <sys/statvfs.h>
+ #include <sys/sysctl.h>
+ #include <sys/types.h>
+ #include <sys/un.h>
+@@ -74,8 +77,8 @@ string GetOutputRoot() {
+ }
+ 
+ void WarnFilesystemType(const blaze_util::Path &output_base) {
+-  struct statfs buf = {};
+-  if (statfs(output_base.AsNativePath().c_str(), &buf) < 0) {
++  struct statvfs buf = {};
++  if (statvfs(output_base.AsNativePath().c_str(), &buf) < 0) {
+     BAZEL_LOG(WARNING) << "couldn't get file system type information for '"
+                        << output_base.AsPrintablePath()
+                        << "': " << strerror(errno);
+@@ -112,7 +115,7 @@ string GetSelfPath(const char* argv0) {
+   }
+   procstat_close(procstat);
+   return string(buffer);
+-#elif defined(__OpenBSD__)
++#elif defined(__OpenBSD__) || defined(__NetBSD__)
+   // OpenBSD does not provide a way for a running process to find a path to its
+   // own executable, so we try to figure out a path by inspecting argv[0]. In
+   // theory this is inadequate, since the parent process can set argv[0] to
diff --git a/bazel/patches/patch-src_main_java_com_google_devtools_build_lib_analysis_ShellConfiguration.java b/bazel/patches/patch-src_main_java_com_google_devtools_build_lib_analysis_ShellConfiguration.java
new file mode 100644
index 0000000000..029e06e3f3
--- /dev/null
+++ b/bazel/patches/patch-src_main_java_com_google_devtools_build_lib_analysis_ShellConfiguration.java
@@ -0,0 +1,16 @@
+$NetBSD$
+
+--- src/main/java/com/google/devtools/build/lib/analysis/ShellConfiguration.java.orig	2023-11-28 16:42:24.000271398 +0000
++++ src/main/java/com/google/devtools/build/lib/analysis/ShellConfiguration.java
+@@ -84,6 +84,11 @@ public class ShellConfiguration extends 
+                   OS_CONSTRAINT_SETTING,
+                   Label.parseAbsoluteUnchecked("@platforms//os:freebsd")))
+           .put(
++              OS.NETBSD,
++              ConstraintValueInfo.create(
++                  OS_CONSTRAINT_SETTING,
++                  Label.parseAbsoluteUnchecked("@platforms//os:netbsd")))
++          .put(
+               OS.OPENBSD,
+               ConstraintValueInfo.create(
+                   OS_CONSTRAINT_SETTING,
diff --git a/bazel/patches/patch-src_main_java_com_google_devtools_build_lib_analysis_config_AutoCpuConverter.java b/bazel/patches/patch-src_main_java_com_google_devtools_build_lib_analysis_config_AutoCpuConverter.java
new file mode 100644
index 0000000000..1510fa0a27
--- /dev/null
+++ b/bazel/patches/patch-src_main_java_com_google_devtools_build_lib_analysis_config_AutoCpuConverter.java
@@ -0,0 +1,22 @@
+$NetBSD$
+
+--- src/main/java/com/google/devtools/build/lib/analysis/config/AutoCpuConverter.java.orig	2023-11-28 16:41:36.908346594 +0000
++++ src/main/java/com/google/devtools/build/lib/analysis/config/AutoCpuConverter.java
+@@ -44,6 +44,8 @@ public class AutoCpuConverter extends Co
+           }
+         case FREEBSD:
+           return "freebsd";
++        case NETBSD:
++          return "netbsd";
+         case OPENBSD:
+           return "openbsd";
+         case WINDOWS:
+@@ -98,6 +100,8 @@ public class AutoCpuConverter extends Co
+       return Pair.of(CPU.getCurrent(), OS.DARWIN);
+     } else if (input.startsWith("freebsd")) {
+       return Pair.of(CPU.getCurrent(), OS.FREEBSD);
++    } else if (input.startsWith("netbsd")) {
++      return Pair.of(CPU.getCurrent(), OS.NETBSD);
+     } else if (input.startsWith("openbsd")) {
+       return Pair.of(CPU.getCurrent(), OS.OPENBSD);
+     } else if (input.startsWith("x64_windows")) {
diff --git a/bazel/patches/patch-src_main_java_com_google_devtools_build_lib_bazel_repository_LocalConfigPlatformFunction.java b/bazel/patches/patch-src_main_java_com_google_devtools_build_lib_bazel_repository_LocalConfigPlatformFunction.java
new file mode 100644
index 0000000000..c0cd0e3240
--- /dev/null
+++ b/bazel/patches/patch-src_main_java_com_google_devtools_build_lib_bazel_repository_LocalConfigPlatformFunction.java
@@ -0,0 +1,13 @@
+$NetBSD$
+
+--- src/main/java/com/google/devtools/build/lib/bazel/repository/LocalConfigPlatformFunction.java.orig	2023-11-28 16:37:24.063463278 +0000
++++ src/main/java/com/google/devtools/build/lib/bazel/repository/LocalConfigPlatformFunction.java
+@@ -135,6 +135,8 @@ public class LocalConfigPlatformFunction
+         return "@platforms//os:osx";
+       case FREEBSD:
+         return "@platforms//os:freebsd";
++      case NETBSD:
++        return "@platforms//os:netbsd";
+       case OPENBSD:
+         return "@platforms//os:openbsd";
+       case LINUX:
diff --git a/bazel/patches/patch-src_main_java_com_google_devtools_build_lib_bazel_rules_BazelRuleClassProvider.java b/bazel/patches/patch-src_main_java_com_google_devtools_build_lib_bazel_rules_BazelRuleClassProvider.java
new file mode 100644
index 0000000000..84ab12ee99
--- /dev/null
+++ b/bazel/patches/patch-src_main_java_com_google_devtools_build_lib_bazel_rules_BazelRuleClassProvider.java
@@ -0,0 +1,12 @@
+$NetBSD$
+
+--- src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRuleClassProvider.java.orig	2023-11-30 05:47:44.632845320 +0000
++++ src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRuleClassProvider.java
+@@ -173,6 +173,7 @@ public class BazelRuleClassProvider {
+       ImmutableMap.<OS, PathFragment>builder()
+           .put(OS.WINDOWS, PathFragment.create("c:/tools/msys64/usr/bin/bash.exe"))
+           .put(OS.FREEBSD, PathFragment.create("/usr/local/bin/bash"))
++          .put(OS.NETBSD, PathFragment.create("/usr/pkg/bin/bash"))
+           .put(OS.OPENBSD, PathFragment.create("/usr/local/bin/bash"))
+           .put(OS.UNKNOWN, FALLBACK_SHELL)
+           .buildOrThrow();
diff --git a/bazel/patches/patch-src_main_java_com_google_devtools_build_lib_jni_JniLoader.java b/bazel/patches/patch-src_main_java_com_google_devtools_build_lib_jni_JniLoader.java
new file mode 100644
index 0000000000..99a465e9a5
--- /dev/null
+++ b/bazel/patches/patch-src_main_java_com_google_devtools_build_lib_jni_JniLoader.java
@@ -0,0 +1,12 @@
+$NetBSD$
+
+--- src/main/java/com/google/devtools/build/lib/jni/JniLoader.java.orig	2023-11-30 05:46:49.398016529 +0000
++++ src/main/java/com/google/devtools/build/lib/jni/JniLoader.java
+@@ -39,6 +39,7 @@ public final class JniLoader {
+       switch (OS.getCurrent()) {
+         case LINUX:
+         case FREEBSD:
++        case NETBSD:
+         case OPENBSD:
+         case UNKNOWN:
+           loadLibrary("main/native/libunix_jni.so");
diff --git a/bazel/patches/patch-src_main_java_com_google_devtools_build_lib_runtime_CommonCommandOptions.java b/bazel/patches/patch-src_main_java_com_google_devtools_build_lib_runtime_CommonCommandOptions.java
new file mode 100644
index 0000000000..3ed03bd1f9
--- /dev/null
+++ b/bazel/patches/patch-src_main_java_com_google_devtools_build_lib_runtime_CommonCommandOptions.java
@@ -0,0 +1,13 @@
+$NetBSD$
+
+--- src/main/java/com/google/devtools/build/lib/runtime/CommonCommandOptions.java.orig	2023-11-28 16:44:31.844523584 +0000
++++ src/main/java/com/google/devtools/build/lib/runtime/CommonCommandOptions.java
+@@ -51,7 +51,7 @@ public class CommonCommandOptions extend
+           "If true, Bazel picks up host-OS-specific config lines from bazelrc files. For example, "
+               + "if the host OS is Linux and you run bazel build, Bazel picks up lines starting "
+               + "with build:linux. Supported OS identifiers are linux, macos, windows, freebsd, "
+-              + "and openbsd. Enabling this flag is equivalent to using --config=linux on Linux, "
++              + "netbsd and openbsd. Enabling this flag is equivalent to using --config=linux on Linux, "
+               + "--config=windows on Windows, etc.")
+   public boolean enablePlatformSpecificConfig;
+ 
diff --git a/bazel/patches/patch-src_main_java_com_google_devtools_build_lib_runtime_ConfigExpander.java b/bazel/patches/patch-src_main_java_com_google_devtools_build_lib_runtime_ConfigExpander.java
new file mode 100644
index 0000000000..a4f3b74e15
--- /dev/null
+++ b/bazel/patches/patch-src_main_java_com_google_devtools_build_lib_runtime_ConfigExpander.java
@@ -0,0 +1,13 @@
+$NetBSD$
+
+--- src/main/java/com/google/devtools/build/lib/runtime/ConfigExpander.java.orig	2023-11-28 16:45:00.372600192 +0000
++++ src/main/java/com/google/devtools/build/lib/runtime/ConfigExpander.java
+@@ -48,6 +48,8 @@ final class ConfigExpander {
+         return "windows";
+       case FREEBSD:
+         return "freebsd";
++      case NETBSD:
++        return "netbsd";
+       case OPENBSD:
+         return "openbsd";
+       default:
diff --git a/bazel/patches/patch-src_main_java_com_google_devtools_build_lib_util_OS.java b/bazel/patches/patch-src_main_java_com_google_devtools_build_lib_util_OS.java
new file mode 100644
index 0000000000..563487e875
--- /dev/null
+++ b/bazel/patches/patch-src_main_java_com_google_devtools_build_lib_util_OS.java
@@ -0,0 +1,19 @@
+$NetBSD$
+
+--- src/main/java/com/google/devtools/build/lib/util/OS.java.orig	1979-12-31 15:00:00.000000000 +0000
++++ src/main/java/com/google/devtools/build/lib/util/OS.java
+@@ -21,12 +21,13 @@ import java.util.EnumSet;
+ public enum OS {
+   DARWIN("osx", "Mac OS X"),
+   FREEBSD("freebsd", "FreeBSD"),
++  NETBSD("netbsd", "NetBSD"),
+   OPENBSD("openbsd", "OpenBSD"),
+   LINUX("linux", "Linux"),
+   WINDOWS("windows", "Windows"),
+   UNKNOWN("unknown", "");
+ 
+-  private static final EnumSet<OS> POSIX_COMPATIBLE = EnumSet.of(DARWIN, FREEBSD, OPENBSD, LINUX);
++  private static final EnumSet<OS> POSIX_COMPATIBLE = EnumSet.of(DARWIN, FREEBSD, NETBSD, OPENBSD, LINUX);
+ 
+   private final String canonicalName;
+   private final String detectionName;
diff --git a/bazel/patches/patch-src_main_native_BUILD b/bazel/patches/patch-src_main_native_BUILD
new file mode 100644
index 0000000000..74f78e7c61
--- /dev/null
+++ b/bazel/patches/patch-src_main_native_BUILD
@@ -0,0 +1,20 @@
+$NetBSD$
+
+--- src/main/native/BUILD.orig	2023-11-28 16:45:20.409299941 +0000
++++ src/main/native/BUILD
+@@ -3,6 +3,7 @@ genrule(
+     srcs = select({
+         "//src/conditions:darwin": ["@bazel_tools//tools/jdk:jni_md_header-darwin"],
+         "//src/conditions:freebsd": ["@bazel_tools//tools/jdk:jni_md_header-freebsd"],
++        "//src/conditions:netbsd": ["@bazel_tools//tools/jdk:jni_md_header-netbsd"],
+         "//src/conditions:openbsd": ["@bazel_tools//tools/jdk:jni_md_header-openbsd"],
+         "//src/conditions:windows": ["@bazel_tools//tools/jdk:jni_md_header-windows"],
+         "//conditions:default": ["@bazel_tools//tools/jdk:jni_md_header-linux"],
+@@ -38,6 +39,7 @@ filegroup(
+             "darwin/util.h",
+         ],
+         "//src/conditions:freebsd": ["unix_jni_bsd.cc"],
++        "//src/conditions:netbsd": ["unix_jni_bsd.cc"],
+         "//src/conditions:openbsd": ["unix_jni_bsd.cc"],
+         "//conditions:default": ["unix_jni_linux.cc"],
+     }),
diff --git a/bazel/patches/patch-src_main_native_unix__jni.h b/bazel/patches/patch-src_main_native_unix__jni.h
new file mode 100644
index 0000000000..e5cfaca1ac
--- /dev/null
+++ b/bazel/patches/patch-src_main_native_unix__jni.h
@@ -0,0 +1,13 @@
+$NetBSD$
+
+--- src/main/native/unix_jni.h.orig	2023-11-29 05:49:36.312797541 +0000
++++ src/main/native/unix_jni.h
+@@ -25,7 +25,7 @@
+ 
+ namespace blaze_jni {
+ 
+-#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__)
++#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
+ // stat64 is deprecated on OS X/BSD.
+ typedef struct stat portable_stat_struct;
+ #define portable_stat ::stat
diff --git a/bazel/patches/patch-src_main_native_unix__jni__bsd.cc b/bazel/patches/patch-src_main_native_unix__jni__bsd.cc
new file mode 100644
index 0000000000..8aad44dd46
--- /dev/null
+++ b/bazel/patches/patch-src_main_native_unix__jni__bsd.cc
@@ -0,0 +1,13 @@
+$NetBSD$
+
+--- src/main/native/unix_jni_bsd.cc.orig	2023-11-28 16:43:12.878427212 +0000
++++ src/main/native/unix_jni_bsd.cc
+@@ -15,6 +15,8 @@
+ #if defined(__FreeBSD__)
+ # define HAVE_EXTATTR
+ # define HAVE_SYSCTLBYNAME
++#elif defined(__NetBSD__)
++// XXX
+ #elif defined(__OpenBSD__)
+ // No sys/extattr.h or sysctlbyname on this platform.
+ #else
diff --git a/bazel/patches/patch-src_main_tools_BUILD b/bazel/patches/patch-src_main_tools_BUILD
new file mode 100644
index 0000000000..7fb0f4c64b
--- /dev/null
+++ b/bazel/patches/patch-src_main_tools_BUILD
@@ -0,0 +1,44 @@
+$NetBSD$
+
+--- src/main/tools/BUILD.orig	2023-11-28 16:45:59.477101665 +0000
++++ src/main/tools/BUILD
+@@ -15,6 +15,7 @@ cc_library(
+     name = "process-tools",
+     srcs = ["process-tools.cc"] + select({
+         "//src/conditions:darwin": ["process-tools-darwin.cc"],
++        "//src/conditions:netbsd": ["process-tools-darwin.cc"],
+         "//src/conditions:openbsd": ["process-tools-darwin.cc"],
+         "//conditions:default": ["process-tools-linux.cc"],
+     }),
+@@ -40,6 +41,7 @@ cc_binary(
+     }),
+     linkopts = select({
+         "//src/conditions:darwin": ["-lm"],
++        "//src/conditions:netbsd": [],
+         "//src/conditions:openbsd": [],
+         "//src/conditions:windows": [],
+         "//conditions:default": [
+@@ -73,6 +75,7 @@ cc_binary(
+     srcs = select({
+         "//src/conditions:darwin": ["dummy-sandbox.c"],
+         "//src/conditions:freebsd": ["dummy-sandbox.c"],
++        "//src/conditions:netbsd": ["dummy-sandbox.c"],
+         "//src/conditions:openbsd": ["dummy-sandbox.c"],
+         "//src/conditions:windows": ["dummy-sandbox.c"],
+         "//conditions:default": [
+@@ -87,6 +90,7 @@ cc_binary(
+     linkopts = select({
+         "//src/conditions:darwin": [],
+         "//src/conditions:freebsd": [],
++        "//src/conditions:netbsd": [],
+         "//src/conditions:openbsd": [],
+         "//src/conditions:windows": [],
+         "//conditions:default": [
+@@ -97,6 +101,7 @@ cc_binary(
+     deps = select({
+         "//src/conditions:darwin": [],
+         "//src/conditions:freebsd": [],
++        "//src/conditions:netbsd": [],
+         "//src/conditions:openbsd": [],
+         "//src/conditions:windows": [],
+         "//conditions:default": [
diff --git a/bazel/patches/patch-src_main_tools_process-tools-darwin.cc b/bazel/patches/patch-src_main_tools_process-tools-darwin.cc
new file mode 100644
index 0000000000..5d5094b23d
--- /dev/null
+++ b/bazel/patches/patch-src_main_tools_process-tools-darwin.cc
@@ -0,0 +1,24 @@
+$NetBSD$
+
+--- src/main/tools/process-tools-darwin.cc.orig	2023-11-30 00:21:24.455150308 +0000
++++ src/main/tools/process-tools-darwin.cc
+@@ -24,6 +24,10 @@
+ #include "src/main/tools/logging.h"
+ #include "src/main/tools/process-tools.h"
+ 
++#if defined(__NetBSD__)
++#define kinfo_proc kinfo_proc2
++#endif
++
+ int WaitForProcessToTerminate(pid_t pid) {
+   int kq;
+   if ((kq = kqueue()) == -1) {
+@@ -93,7 +97,7 @@ int WaitForProcessGroupToTerminate(pid_t
+     if (nprocs == 1) {
+       // Found only one process, which must be the leader because we have
+       // purposely expect it as a zombie with WaitForProcess.
+-#if defined(__OpenBSD__)
++#if defined(__OpenBSD__) || defined(__NetBSD__)
+       if (procs->p_pid != pgid) {
+ #else
+       if (procs->kp_proc.p_pid != pgid) {
diff --git a/bazel/patches/patch-src_test_java_com_google_devtools_build_lib_bazel_repository_LocalConfigPlatformFunctionTest.java b/bazel/patches/patch-src_test_java_com_google_devtools_build_lib_bazel_repository_LocalConfigPlatformFunctionTest.java
new file mode 100644
index 0000000000..4e06e18120
--- /dev/null
+++ b/bazel/patches/patch-src_test_java_com_google_devtools_build_lib_bazel_repository_LocalConfigPlatformFunctionTest.java
@@ -0,0 +1,12 @@
+$NetBSD$
+
+--- src/test/java/com/google/devtools/build/lib/bazel/repository/LocalConfigPlatformFunctionTest.java.orig	2023-11-28 16:47:43.460647791 +0000
++++ src/test/java/com/google/devtools/build/lib/bazel/repository/LocalConfigPlatformFunctionTest.java
+@@ -87,6 +87,7 @@ public class LocalConfigPlatformFunction
+           new Object[] {OS.LINUX, "@platforms//os:linux"},
+           new Object[] {OS.DARWIN, "@platforms//os:osx"},
+           new Object[] {OS.FREEBSD, "@platforms//os:freebsd"},
++          new Object[] {OS.NETBSD, "@platforms//os:netbsd"},
+           new Object[] {OS.OPENBSD, "@platforms//os:openbsd"},
+           new Object[] {OS.WINDOWS, "@platforms//os:windows"});
+     }
diff --git a/bazel/patches/patch-src_test_java_com_google_devtools_build_lib_bazel_rules_BazelRuleClassProviderTest.java b/bazel/patches/patch-src_test_java_com_google_devtools_build_lib_bazel_rules_BazelRuleClassProviderTest.java
new file mode 100644
index 0000000000..ce6817e742
--- /dev/null
+++ b/bazel/patches/patch-src_test_java_com_google_devtools_build_lib_bazel_rules_BazelRuleClassProviderTest.java
@@ -0,0 +1,22 @@
+$NetBSD$
+
+--- src/test/java/com/google/devtools/build/lib/bazel/rules/BazelRuleClassProviderTest.java.orig	2023-11-30 05:50:35.115838020 +0000
++++ src/test/java/com/google/devtools/build/lib/bazel/rules/BazelRuleClassProviderTest.java
+@@ -218,6 +218,8 @@ public class BazelRuleClassProviderTest 
+         .isEqualTo(PathFragment.create("/bin/bash"));
+     assertThat(determineShellExecutable(OS.FREEBSD, null))
+         .isEqualTo(PathFragment.create("/usr/local/bin/bash"));
++    assertThat(determineShellExecutable(OS.NETBSD, null))
++        .isEqualTo(PathFragment.create("/usr/pkg/bin/bash"));
+     assertThat(determineShellExecutable(OS.OPENBSD, null))
+         .isEqualTo(PathFragment.create("/usr/local/bin/bash"));
+     assertThat(determineShellExecutable(OS.WINDOWS, null))
+@@ -231,6 +233,8 @@ public class BazelRuleClassProviderTest 
+         .isEqualTo(PathFragment.create("/bin/bash"));
+     assertThat(determineShellExecutable(OS.FREEBSD, binBash))
+         .isEqualTo(PathFragment.create("/bin/bash"));
++    assertThat(determineShellExecutable(OS.NETBSD, binBash))
++        .isEqualTo(PathFragment.create("/bin/bash"));
+     assertThat(determineShellExecutable(OS.OPENBSD, binBash))
+         .isEqualTo(PathFragment.create("/bin/bash"));
+     assertThat(determineShellExecutable(OS.WINDOWS, binBash))
diff --git a/bazel/patches/patch-src_test_java_com_google_devtools_build_lib_packages_util_MockPlatformSupport.java b/bazel/patches/patch-src_test_java_com_google_devtools_build_lib_packages_util_MockPlatformSupport.java
new file mode 100644
index 0000000000..f42adcf534
--- /dev/null
+++ b/bazel/patches/patch-src_test_java_com_google_devtools_build_lib_packages_util_MockPlatformSupport.java
@@ -0,0 +1,15 @@
+$NetBSD$
+
+--- src/test/java/com/google/devtools/build/lib/packages/util/MockPlatformSupport.java.orig	2023-11-28 16:47:15.246726723 +0000
++++ src/test/java/com/google/devtools/build/lib/packages/util/MockPlatformSupport.java
+@@ -136,6 +136,10 @@ public class MockPlatformSupport {
+         "    constraint_setting = ':os',",
+         ")",
+         "constraint_value(",
++        "    name = 'netbsd',",
++        "    constraint_setting = ':os',",
++        ")",
++        "constraint_value(",
+         "    name = 'openbsd',",
+         "    constraint_setting = ':os',",
+         ")");
diff --git a/bazel/patches/patch-src_test_java_com_google_devtools_build_lib_platform_SleepPreventionModuleTest.java b/bazel/patches/patch-src_test_java_com_google_devtools_build_lib_platform_SleepPreventionModuleTest.java
new file mode 100644
index 0000000000..a3c86d250e
--- /dev/null
+++ b/bazel/patches/patch-src_test_java_com_google_devtools_build_lib_platform_SleepPreventionModuleTest.java
@@ -0,0 +1,12 @@
+$NetBSD$
+
+--- src/test/java/com/google/devtools/build/lib/platform/SleepPreventionModuleTest.java.orig	2023-11-30 05:51:43.180401312 +0000
++++ src/test/java/com/google/devtools/build/lib/platform/SleepPreventionModuleTest.java
+@@ -32,6 +32,7 @@ public final class SleepPreventionModule
+         return true;
+       case LINUX:
+       case FREEBSD:
++      case NETBSD:
+       case OPENBSD:
+       case UNKNOWN:
+         return false;
diff --git a/bazel/patches/patch-src_test_java_com_google_devtools_build_lib_runtime_BlazeOptionHandlerTest.java b/bazel/patches/patch-src_test_java_com_google_devtools_build_lib_runtime_BlazeOptionHandlerTest.java
new file mode 100644
index 0000000000..b35792c191
--- /dev/null
+++ b/bazel/patches/patch-src_test_java_com_google_devtools_build_lib_runtime_BlazeOptionHandlerTest.java
@@ -0,0 +1,32 @@
+$NetBSD$
+
+--- src/test/java/com/google/devtools/build/lib/runtime/BlazeOptionHandlerTest.java.orig	2023-11-28 16:50:58.267394320 +0000
++++ src/test/java/com/google/devtools/build/lib/runtime/BlazeOptionHandlerTest.java
+@@ -117,6 +117,7 @@ public class BlazeOptionHandlerTest {
+     structuredArgs.put("c0:windows", new RcChunkOfArgs("rc1", ImmutableList.of("command_windows")));
+     structuredArgs.put("c0:macos", new RcChunkOfArgs("rc1", ImmutableList.of("command_macos")));
+     structuredArgs.put("c0:freebsd", new RcChunkOfArgs("rc1", ImmutableList.of("command_freebsd")));
++    structuredArgs.put("c0:netbsd", new RcChunkOfArgs("rc1", ImmutableList.of("command_netbsd")));
+     structuredArgs.put("c0:openbsd", new RcChunkOfArgs("rc1", ImmutableList.of("command_openbsd")));
+     structuredArgs.put(
+         "c0:platform_config",
+@@ -283,6 +284,9 @@ public class BlazeOptionHandlerTest {
+       case FREEBSD:
+         assertThat(parser.getResidue()).containsExactly("command_freebsd");
+         break;
++      case NETBSD:
++        assertThat(parser.getResidue()).containsExactly("command_netbsd");
++        break;
+       case OPENBSD:
+         assertThat(parser.getResidue()).containsExactly("command_openbsd");
+         break;
+@@ -311,6 +315,9 @@ public class BlazeOptionHandlerTest {
+       case FREEBSD:
+         assertThat(parser.getResidue()).containsExactly("command_freebsd");
+         break;
++      case NETBSD:
++        assertThat(parser.getResidue()).containsExactly("command_netbsd");
++        break;
+       case OPENBSD:
+         assertThat(parser.getResidue()).containsExactly("command_openbsd");
+         break;
diff --git a/bazel/patches/patch-src_test_java_com_google_devtools_build_lib_runtime_commands_CleanCommandRecommendsAsyncTest.java b/bazel/patches/patch-src_test_java_com_google_devtools_build_lib_runtime_commands_CleanCommandRecommendsAsyncTest.java
new file mode 100644
index 0000000000..4b316d8b80
--- /dev/null
+++ b/bazel/patches/patch-src_test_java_com_google_devtools_build_lib_runtime_commands_CleanCommandRecommendsAsyncTest.java
@@ -0,0 +1,20 @@
+$NetBSD$
+
+--- src/test/java/com/google/devtools/build/lib/runtime/commands/CleanCommandRecommendsAsyncTest.java.orig	2023-11-30 05:52:55.919903525 +0000
++++ src/test/java/com/google/devtools/build/lib/runtime/commands/CleanCommandRecommendsAsyncTest.java
+@@ -51,6 +51,7 @@ public class CleanCommandRecommendsAsync
+           {/* asyncOnCommandLine= */ true, OS.WINDOWS, false},
+           {/* asyncOnCommandLine= */ true, OS.DARWIN, false},
+           {/* asyncOnCommandLine= */ true, OS.FREEBSD, false},
++          {/* asyncOnCommandLine= */ true, OS.NETBSD, false},
+           {/* asyncOnCommandLine= */ true, OS.OPENBSD, false},
+           {/* asyncOnCommandLine= */ true, OS.UNKNOWN, false},
+ 
+@@ -59,6 +60,7 @@ public class CleanCommandRecommendsAsync
+           {/* asyncOnCommandLine= */ false, OS.WINDOWS, false},
+           {/* asyncOnCommandLine= */ false, OS.DARWIN, true},
+           {/* asyncOnCommandLine= */ false, OS.FREEBSD, true},
++          {/* asyncOnCommandLine= */ false, OS.NETBSD, true},
+           {/* asyncOnCommandLine= */ false, OS.OPENBSD, true},
+           {/* asyncOnCommandLine= */ false, OS.UNKNOWN, false},
+         });
diff --git a/bazel/patches/patch-src_test_shell_bazel_remote_remote__execution__test.sh b/bazel/patches/patch-src_test_shell_bazel_remote_remote__execution__test.sh
new file mode 100644
index 0000000000..1969608568
--- /dev/null
+++ b/bazel/patches/patch-src_test_shell_bazel_remote_remote__execution__test.sh
@@ -0,0 +1,22 @@
+$NetBSD$
+
+--- src/test/shell/bazel/remote/remote_execution_test.sh.orig	2023-11-28 16:48:56.932298505 +0000
++++ src/test/shell/bazel/remote/remote_execution_test.sh
+@@ -197,7 +197,7 @@ EOF
+ # TODO(b/211478955): Deflake and re-enable.
+ function DISABLED_test_remote_grpc_via_unix_socket_proxy() {
+   case "$PLATFORM" in
+-  darwin|freebsd|linux|openbsd)
++  darwin|freebsd|linux|openbsd|netbsd)
+     ;;
+   *)
+     return 0
+@@ -236,7 +236,7 @@ EOF
+ # TODO(b/211478955): Deflake and re-enable.
+ function DISABLED_test_remote_grpc_via_unix_socket_direct() {
+   case "$PLATFORM" in
+-  darwin|freebsd|linux|openbsd)
++  darwin|freebsd|linux|openbsd|netbsd)
+     ;;
+   *)
+     return 0
diff --git a/bazel/patches/patch-src_test_shell_bazel_unicode__filenames__test.sh b/bazel/patches/patch-src_test_shell_bazel_unicode__filenames__test.sh
new file mode 100644
index 0000000000..d855fc94cf
--- /dev/null
+++ b/bazel/patches/patch-src_test_shell_bazel_unicode__filenames__test.sh
@@ -0,0 +1,13 @@
+$NetBSD$
+
+--- src/test/shell/bazel/unicode_filenames_test.sh.orig	2023-11-28 16:49:24.316954368 +0000
++++ src/test/shell/bazel/unicode_filenames_test.sh
+@@ -142,7 +142,7 @@ function test_traditional_encoding_sourc
+   # the traditional BSDs typically don't, so their paths can contain arbitrary
+   # non-NUL bytes.
+   case "$(uname -s | tr [:upper:] [:lower:])" in
+-  linux|freebsd)
++  linux|freebsd|netbsd)
+     ;;
+   *)
+     echo "Skipping test." && return
diff --git a/bazel/patches/patch-src_test_shell_shell__utils.sh b/bazel/patches/patch-src_test_shell_shell__utils.sh
new file mode 100644
index 0000000000..95117c5470
--- /dev/null
+++ b/bazel/patches/patch-src_test_shell_shell__utils.sh
@@ -0,0 +1,13 @@
+$NetBSD$
+
+--- src/test/shell/shell_utils.sh.orig	2023-11-28 16:48:06.068223021 +0000
++++ src/test/shell/shell_utils.sh
+@@ -110,7 +110,7 @@ function get_real_path() {
+ function md5_file() {
+   if [ $# -gt 0 ]; then
+     local result=""
+-    if [[ ${PLATFORM} == "darwin" ]] || [[ ${PLATFORM} == "freebsd" ]] || [[ ${PLATFORM} == "openbsd" ]]; then
++    if [[ ${PLATFORM} == "darwin" ]] || [[ ${PLATFORM} == "freebsd" ]] || [[ ${PLATFORM} == "netbsd" ]] || [[ ${PLATFORM} == "openbsd" ]]; then
+       result=$(md5 -q $@ || echo)
+     else
+       result=$(md5sum $@ | awk '{print $1}' || echo)
diff --git a/bazel/patches/patch-src_tools_singlejar_BUILD b/bazel/patches/patch-src_tools_singlejar_BUILD
new file mode 100644
index 0000000000..29a0f7e88e
--- /dev/null
+++ b/bazel/patches/patch-src_tools_singlejar_BUILD
@@ -0,0 +1,20 @@
+$NetBSD$
+
+--- src/tools/singlejar/BUILD.orig	2023-11-28 16:49:45.631463476 +0000
++++ src/tools/singlejar/BUILD
+@@ -76,6 +76,7 @@ cc_binary(
+     ],
+     linkopts = select({
+         "//src/conditions:freebsd": ["-lm"],
++        "//src/conditions:netbsd": ["-lm"],
+         "//src/conditions:openbsd": ["-lm"],
+         "//conditions:default": [],
+     }),
+@@ -95,6 +96,7 @@ cc_binary(
+     ],
+     linkopts = select({
+         "//src/conditions:freebsd": ["-lm"],
++        "//src/conditions:netbsd": ["-lm"],
+         "//src/conditions:openbsd": ["-lm"],
+         "//conditions:default": [],
+     }),
diff --git a/bazel/patches/patch-src_tools_singlejar_diag.h b/bazel/patches/patch-src_tools_singlejar_diag.h
new file mode 100644
index 0000000000..78a8737058
--- /dev/null
+++ b/bazel/patches/patch-src_tools_singlejar_diag.h
@@ -0,0 +1,13 @@
+$NetBSD$
+
+--- src/tools/singlejar/diag.h.orig	2023-11-29 01:42:21.128823620 +0000
++++ src/tools/singlejar/diag.h
+@@ -20,7 +20,7 @@
+  * for portability.
+  */
+ #if defined(__APPLE__) || defined(__linux__) || defined(__FreeBSD__) || \
+-    defined(__OpenBSD__)
++    defined(__OpenBSD__) || defined(__NetBSD__)
+ 
+ #include <err.h>
+ #define diag_err(...) err(__VA_ARGS__)
diff --git a/bazel/patches/patch-src_tools_singlejar_mapped__file__posix.inc b/bazel/patches/patch-src_tools_singlejar_mapped__file__posix.inc
new file mode 100644
index 0000000000..dd3c0fd159
--- /dev/null
+++ b/bazel/patches/patch-src_tools_singlejar_mapped__file__posix.inc
@@ -0,0 +1,13 @@
+$NetBSD$
+
+--- src/tools/singlejar/mapped_file_posix.inc.orig	2023-11-29 01:55:21.101251891 +0000
++++ src/tools/singlejar/mapped_file_posix.inc
+@@ -26,7 +26,7 @@
+ 
+ // The implementation is specific to 64-bit Linux / OS X / BSD.
+ #if !((defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || \
+-       defined(__OpenBSD__)) &&                                            \
++       defined(__OpenBSD__) || defined(__NetBSD__)) &&                                            \
+       __SIZEOF_POINTER__ == 8)
+ #error This code for 64 bit Unix.
+ #endif
diff --git a/bazel/patches/patch-src_tools_singlejar_port.h b/bazel/patches/patch-src_tools_singlejar_port.h
new file mode 100644
index 0000000000..ded55de2bc
--- /dev/null
+++ b/bazel/patches/patch-src_tools_singlejar_port.h
@@ -0,0 +1,13 @@
+$NetBSD$
+
+--- src/tools/singlejar/port.h.orig	2023-11-29 01:53:34.029841579 +0000
++++ src/tools/singlejar/port.h
+@@ -32,7 +32,7 @@
+ typedef off_t off64_t;
+ #elif defined(_WIN32)
+ typedef __int64 off64_t;
+-#elif defined(__OpenBSD__)
++#elif defined(__OpenBSD__) || defined(__NetBSD__)
+ typedef int64_t off64_t;
+ #endif
+ static_assert(sizeof(off64_t) == 8, "File offset type must be 64-bit");
diff --git a/bazel/patches/patch-src_tools_singlejar_zip__headers.h b/bazel/patches/patch-src_tools_singlejar_zip__headers.h
new file mode 100644
index 0000000000..6eedefd175
--- /dev/null
+++ b/bazel/patches/patch-src_tools_singlejar_zip__headers.h
@@ -0,0 +1,13 @@
+$NetBSD$
+
+--- src/tools/singlejar/zip_headers.h.orig	2023-11-29 01:51:37.732181412 +0000
++++ src/tools/singlejar/zip_headers.h
+@@ -27,7 +27,7 @@
+ 
+ #if defined(__linux__)
+ #include <endian.h>
+-#elif defined(__FreeBSD__) || defined(__OpenBSD__)
++#elif defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
+ #include <sys/endian.h>
+ #elif defined(__APPLE__) || defined(_WIN32)
+ // Hopefully OSX and Windows will keep running solely on little endian CPUs, so:
diff --git a/bazel/patches/patch-third__party_BUILD b/bazel/patches/patch-third__party_BUILD
new file mode 100644
index 0000000000..7a6cc2b6fb
--- /dev/null
+++ b/bazel/patches/patch-third__party_BUILD
@@ -0,0 +1,24 @@
+$NetBSD$
+
+--- third_party/BUILD.orig	2023-11-28 16:50:15.975516749 +0000
++++ third_party/BUILD
+@@ -625,6 +625,7 @@ UNNECESSARY_DYNAMIC_LIBRARIES = select({
+     "//src/conditions:linux_ppc": "*.so *.jnilib *.dll",
+     "//src/conditions:linux_s390x": "*.so *.jnilib *.dll",
+     "//src/conditions:freebsd": "*.so *.jnilib *.dll",
++    "//src/conditions:netbsd": "*.so *.jnilib *.dll",
+     "//src/conditions:openbsd": "*.so *.jnilib *.dll",
+     # Default is to play it safe -- better have a big binary than a slow binary
+     #   The empty string means nothing is to be removed from the library;
+@@ -899,6 +900,11 @@ config_setting(
+ )
+ 
+ config_setting(
++    name = "netbsd",
++    values = {"host_cpu": "netbsd"},
++)
++
++config_setting(
+     name = "openbsd",
+     values = {"host_cpu": "openbsd"},
+ )
diff --git a/bazel/patches/patch-third__party_abseil-cpp_netbsd-sunos.patch b/bazel/patches/patch-third__party_abseil-cpp_netbsd-sunos.patch
new file mode 100644
index 0000000000..ab458114bc
--- /dev/null
+++ b/bazel/patches/patch-third__party_abseil-cpp_netbsd-sunos.patch
@@ -0,0 +1,90 @@
+$NetBSD$
+
+--- third_party/abseil-cpp/netbsd-sunos.patch.orig	2023-11-29 10:06:39.399538673 +0000
++++ third_party/abseil-cpp/netbsd-sunos.patch
+@@ -0,0 +1,85 @@
++--- absl/debugging/internal/vdso_support.cc	2021-11-04 00:26:14.000000000 +0900
+++++ absl/debugging/internal/vdso_support.cc	2023-11-29 18:58:33.941707708 +0900
++@@ -50,8 +50,14 @@
++ #define AT_SYSINFO_EHDR 33  // for crosstoolv10
++ #endif
++ 
+++#if defined(__NetBSD__)
+++using Elf32_auxv_t = Aux32Info;
+++using Elf64_auxv_t = Aux64Info;
+++#endif
++ #if defined(__FreeBSD__)
+++#if defined(__ELF_WORD_SIZE) && __ELF_WORD_SIZE == 64
++ using Elf64_auxv_t = Elf64_Auxinfo;
+++#endif
++ using Elf32_auxv_t = Elf32_Auxinfo;
++ #endif
++ 
++@@ -93,6 +101,9 @@
++     }
++   }
++ #endif  // ABSL_HAVE_GETAUXVAL
+++#if defined(__sun)
+++      return nullptr;
+++#else // !__sun
++   if (vdso_base_.load(std::memory_order_relaxed) == kInvalidBase) {
++     int fd = open("/proc/self/auxv", O_RDONLY);
++     if (fd == -1) {
++@@ -104,8 +115,13 @@
++     ElfW(auxv_t) aux;
++     while (read(fd, &aux, sizeof(aux)) == sizeof(aux)) {
++       if (aux.a_type == AT_SYSINFO_EHDR) {
+++#if defined(__NetBSD__)
+++        vdso_base_.store(reinterpret_cast<void *>(aux.a_v),
+++                         std::memory_order_relaxed);
+++#else
++         vdso_base_.store(reinterpret_cast<void *>(aux.a_un.a_val),
++                          std::memory_order_relaxed);
+++#endif
++         break;
++       }
++     }
++@@ -127,6 +143,7 @@
++   // from assigning to getcpu_fn_ more than once.
++   getcpu_fn_.store(fn, std::memory_order_relaxed);
++   return vdso_base_.load(std::memory_order_relaxed);
+++#endif // __sun
++ }
++ 
++ const void *VDSOSupport::SetBase(const void *base) {
++
++--- absl/debugging/internal/elf_mem_image.cc	2021-11-04 00:26:14.000000000 +0900
+++++ absl/debugging/internal/elf_mem_image.cc	2023-09-18 23:40:01.000000000 +0900
++@@ -351,7 +350,11 @@
++   const ElfW(Versym) *version_symbol = image->GetVersym(index_);
++   ABSL_RAW_CHECK(symbol && version_symbol, "");
++   const char *const symbol_name = image->GetDynstr(symbol->st_name);
+++#if defined(__NetBSD__)
+++  const int version_index = version_symbol->vs_vers & VERSYM_VERSION;
+++#else
++   const ElfW(Versym) version_index = version_symbol[0] & VERSYM_VERSION;
+++#endif
++   const ElfW(Verdef) *version_definition = nullptr;
++   const char *version_name = "";
++   if (symbol->st_shndx == SHN_UNDEF) {
++
++--- absl/base/config.h.orig	2023-11-29 11:18:01.165394118 +0000
+++++ absl/base/config.h
++@@ -414,7 +414,7 @@ static_assert(ABSL_INTERNAL_INLINE_NAMES
++     defined(_AIX) || defined(__ros__) || defined(__native_client__) ||    \
++     defined(__asmjs__) || defined(__wasm__) || defined(__Fuchsia__) ||    \
++     defined(__sun) || defined(__ASYLO__) || defined(__myriad2__) ||       \
++-    defined(__HAIKU__)
+++    defined(__HAIKU__) || defined(__NetBSD__)
++ #define ABSL_HAVE_MMAP 1
++ #endif
++ 
++@@ -425,7 +425,7 @@ static_assert(ABSL_INTERNAL_INLINE_NAMES
++ #ifdef ABSL_HAVE_PTHREAD_GETSCHEDPARAM
++ #error ABSL_HAVE_PTHREAD_GETSCHEDPARAM cannot be directly set
++ #elif defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || \
++-    defined(_AIX) || defined(__ros__)
+++    defined(_AIX) || defined(__ros__) || defined(__NetBSD__)
++ #define ABSL_HAVE_PTHREAD_GETSCHEDPARAM 1
++ #endif
++ 
diff --git a/bazel/patches/patch-third__party_grpc_netbsd-config.patch b/bazel/patches/patch-third__party_grpc_netbsd-config.patch
new file mode 100644
index 0000000000..6ee8c6b3f3
--- /dev/null
+++ b/bazel/patches/patch-third__party_grpc_netbsd-config.patch
@@ -0,0 +1,546 @@
+$NetBSD$
+
+--- third_party/grpc/netbsd-config.patch.orig	2023-11-30 14:45:15.969407560 +0000
++++ third_party/grpc/netbsd-config.patch
+@@ -0,0 +1,541 @@
++diff -urN grpc-1.47.0.orig/third_party/cares/BUILD grpc-1.47.0/third_party/cares/BUILD
++--- grpc-1.47.0.orig/third_party/cares/BUILD	2022-06-22 05:39:47.000000000 +0900
+++++ grpc-1.47.0/third_party/cares/BUILD	2023-11-30 22:06:53.041336686 +0900
++@@ -7,4 +7,5 @@
++     "config_linux/ares_config.h",
++     "config_openbsd/ares_config.h",
++     "config_windows/ares_config.h",
+++    "config_netbsd/ares_config.h",
++ ])
++diff -urN grpc-1.47.0.orig/third_party/cares/cares.BUILD grpc-1.47.0/third_party/cares/cares.BUILD
++--- grpc-1.47.0.orig/third_party/cares/cares.BUILD	2022-06-22 05:39:47.000000000 +0900
+++++ grpc-1.47.0/third_party/cares/cares.BUILD	2023-11-30 23:45:01.919685194 +0900
++@@ -88,6 +88,11 @@
++     values = {"cpu": "watchos_arm64_32"}
++ )
++ 
+++config_setting(
+++    name = "netbsd",
+++    values = {"cpu": "netbsd"},
+++)
+++
++ copy_file(
++     name = "ares_build_h",
++     src = "@com_github_grpc_grpc//third_party/cares:ares_build.h",
++@@ -113,6 +118,7 @@
++         ":darwin_arm64e": "@com_github_grpc_grpc//third_party/cares:config_darwin/ares_config.h",
++         ":windows": "@com_github_grpc_grpc//third_party/cares:config_windows/ares_config.h",
++         ":android": "@com_github_grpc_grpc//third_party/cares:config_android/ares_config.h",
+++        ":netbsd": "@com_github_grpc_grpc//third_party/cares:config_netbsd/ares_config.h",
++         "//conditions:default": "@com_github_grpc_grpc//third_party/cares:config_linux/ares_config.h",
++     }),
++     out = "ares_config.h",
++diff -urN grpc-1.47.0.orig/third_party/cares/config_netbsd/ares_config.h grpc-1.47.0/third_party/cares/config_netbsd/ares_config.h
++--- grpc-1.47.0.orig/third_party/cares/config_netbsd/ares_config.h	1970-01-01 09:00:00.000000000 +0900
+++++ grpc-1.47.0/third_party/cares/config_netbsd/ares_config.h	2023-11-30 23:08:42.228971343 +0900
++@@ -0,0 +1,505 @@
+++/* ares_config.h.  Generated from ares_config.h.in by configure.  */
+++/* ares_config.h.in.  Generated from configure.ac by autoheader.  */
+++
+++/* Define if building universal (internal helper macro) */
+++/* #undef AC_APPLE_UNIVERSAL_BUILD */
+++
+++/* define this if ares is built for a big endian system */
+++/* #undef ARES_BIG_ENDIAN */
+++
+++/* when building as static part of libcurl */
+++/* #undef BUILDING_LIBCURL */
+++
+++/* Defined for build that exposes internal static functions for testing. */
+++/* #undef CARES_EXPOSE_STATICS */
+++
+++/* Defined for build with symbol hiding. */
+++#define CARES_SYMBOL_HIDING 1
+++
+++/* Definition to make a library symbol externally visible. */
+++#define CARES_SYMBOL_SCOPE_EXTERN __attribute__ ((__visibility__ ("default")))
+++
+++/* the signed version of size_t */
+++#define CARES_TYPEOF_ARES_SSIZE_T ssize_t
+++
+++/* Use resolver library to configure cares */
+++/* #undef CARES_USE_LIBRESOLV */
+++
+++/* if a /etc/inet dir is being used */
+++/* #undef ETC_INET */
+++
+++/* Define to the type of arg 2 for gethostname. */
+++#define GETHOSTNAME_TYPE_ARG2 size_t
+++
+++/* Define to the type qualifier of arg 1 for getnameinfo. */
+++#define GETNAMEINFO_QUAL_ARG1 const
+++
+++/* Define to the type of arg 1 for getnameinfo. */
+++#define GETNAMEINFO_TYPE_ARG1 struct sockaddr *
+++
+++/* Define to the type of arg 2 for getnameinfo. */
+++#define GETNAMEINFO_TYPE_ARG2 socklen_t
+++
+++/* Define to the type of args 4 and 6 for getnameinfo. */
+++#define GETNAMEINFO_TYPE_ARG46 size_t
+++
+++/* Define to the type of arg 7 for getnameinfo. */
+++#define GETNAMEINFO_TYPE_ARG7 int
+++
+++/* Specifies the number of arguments to getservbyport_r */
+++#define GETSERVBYPORT_R_ARGS 4
+++
+++/* Specifies the size of the buffer to pass to getservbyport_r */
+++#define GETSERVBYPORT_R_BUFSIZE sizeof(struct servent_data)
+++
+++/* Define to 1 if you have AF_INET6. */
+++#define HAVE_AF_INET6 1
+++
+++/* Define to 1 if you have the <arpa/inet.h> header file. */
+++#define HAVE_ARPA_INET_H 1
+++
+++/* Define to 1 if you have the <arpa/nameser_compat.h> header file. */
+++/* #undef HAVE_ARPA_NAMESER_COMPAT_H */
+++
+++/* Define to 1 if you have the <arpa/nameser.h> header file. */
+++#define HAVE_ARPA_NAMESER_H 1
+++
+++/* Define to 1 if you have the <assert.h> header file. */
+++#define HAVE_ASSERT_H 1
+++
+++/* Define to 1 if you have the `bitncmp' function. */
+++/* #undef HAVE_BITNCMP */
+++
+++/* Define to 1 if bool is an available type. */
+++#define HAVE_BOOL_T 1
+++
+++/* Define to 1 if you have the clock_gettime function and monotonic timer. */
+++#define HAVE_CLOCK_GETTIME_MONOTONIC 1
+++
+++/* Define to 1 if you have the closesocket function. */
+++/* #undef HAVE_CLOSESOCKET */
+++
+++/* Define to 1 if you have the CloseSocket camel case function. */
+++/* #undef HAVE_CLOSESOCKET_CAMEL */
+++
+++/* Define to 1 if you have the connect function. */
+++#define HAVE_CONNECT 1
+++
+++/* define if the compiler supports basic C++11 syntax */
+++/* #undef HAVE_CXX11 */
+++
+++/* Define to 1 if you have the <dlfcn.h> header file. */
+++#define HAVE_DLFCN_H 1
+++
+++/* Define to 1 if you have the <errno.h> header file. */
+++#define HAVE_ERRNO_H 1
+++
+++/* Define to 1 if you have the fcntl function. */
+++#define HAVE_FCNTL 1
+++
+++/* Define to 1 if you have the <fcntl.h> header file. */
+++#define HAVE_FCNTL_H 1
+++
+++/* Define to 1 if you have a working fcntl O_NONBLOCK function. */
+++#define HAVE_FCNTL_O_NONBLOCK 1
+++
+++/* Define to 1 if you have the freeaddrinfo function. */
+++#define HAVE_FREEADDRINFO 1
+++
+++/* Define to 1 if you have a working getaddrinfo function. */
+++#define HAVE_GETADDRINFO 1
+++
+++/* Define to 1 if the getaddrinfo function is threadsafe. */
+++/* #undef HAVE_GETADDRINFO_THREADSAFE */
+++
+++/* Define to 1 if you have the getenv function. */
+++#define HAVE_GETENV 1
+++
+++/* Define to 1 if you have the gethostbyaddr function. */
+++#define HAVE_GETHOSTBYADDR 1
+++
+++/* Define to 1 if you have the gethostbyname function. */
+++#define HAVE_GETHOSTBYNAME 1
+++
+++/* Define to 1 if you have the gethostname function. */
+++#define HAVE_GETHOSTNAME 1
+++
+++/* Define to 1 if you have the getnameinfo function. */
+++#define HAVE_GETNAMEINFO 1
+++
+++/* Define to 1 if you have the getservbyport_r function. */
+++/* #undef HAVE_GETSERVBYPORT_R */
+++
+++/* Define to 1 if you have the `gettimeofday' function. */
+++#define HAVE_GETTIMEOFDAY 1
+++
+++/* Define to 1 if you have the `if_indextoname' function. */
+++#define HAVE_IF_INDEXTONAME 1
+++
+++/* Define to 1 if you have a IPv6 capable working inet_net_pton function. */
+++/* #undef HAVE_INET_NET_PTON */
+++
+++/* Define to 1 if you have a IPv6 capable working inet_ntop function. */
+++#define HAVE_INET_NTOP 1
+++
+++/* Define to 1 if you have a IPv6 capable working inet_pton function. */
+++#define HAVE_INET_PTON 1
+++
+++/* Define to 1 if you have the <inttypes.h> header file. */
+++#define HAVE_INTTYPES_H 1
+++
+++/* Define to 1 if you have the ioctl function. */
+++#define HAVE_IOCTL 1
+++
+++/* Define to 1 if you have the ioctlsocket function. */
+++/* #undef HAVE_IOCTLSOCKET */
+++
+++/* Define to 1 if you have the IoctlSocket camel case function. */
+++/* #undef HAVE_IOCTLSOCKET_CAMEL */
+++
+++/* Define to 1 if you have a working IoctlSocket camel case FIONBIO function.
+++   */
+++/* #undef HAVE_IOCTLSOCKET_CAMEL_FIONBIO */
+++
+++/* Define to 1 if you have a working ioctlsocket FIONBIO function. */
+++/* #undef HAVE_IOCTLSOCKET_FIONBIO */
+++
+++/* Define to 1 if you have a working ioctl FIONBIO function. */
+++#define HAVE_IOCTL_FIONBIO 1
+++
+++/* Define to 1 if you have a working ioctl SIOCGIFADDR function. */
+++#define HAVE_IOCTL_SIOCGIFADDR 1
+++
+++/* Define to 1 if you have the `resolve' library (-lresolve). */
+++/* #undef HAVE_LIBRESOLVE */
+++
+++/* Define to 1 if you have the <limits.h> header file. */
+++#define HAVE_LIMITS_H 1
+++
+++/* if your compiler supports LL */
+++#define HAVE_LL 1
+++
+++/* Define to 1 if the compiler supports the 'long long' data type. */
+++#define HAVE_LONGLONG 1
+++
+++/* Define to 1 if you have the malloc.h header file. */
+++/* #undef HAVE_MALLOC_H */
+++
+++/* Define to 1 if you have the memory.h header file. */
+++#define HAVE_MEMORY_H 1
+++
+++/* Define to 1 if you have the MSG_NOSIGNAL flag. */
+++#define HAVE_MSG_NOSIGNAL 1
+++
+++/* Define to 1 if you have the <netdb.h> header file. */
+++#define HAVE_NETDB_H 1
+++
+++/* Define to 1 if you have the <netinet/in.h> header file. */
+++#define HAVE_NETINET_IN_H 1
+++
+++/* Define to 1 if you have the <netinet/tcp.h> header file. */
+++#define HAVE_NETINET_TCP_H 1
+++
+++/* Define to 1 if you have the <net/if.h> header file. */
+++#define HAVE_NET_IF_H 1
+++
+++/* Define to 1 if you have PF_INET6. */
+++#define HAVE_PF_INET6 1
+++
+++/* Define to 1 if you have the recv function. */
+++#define HAVE_RECV 1
+++
+++/* Define to 1 if you have the recvfrom function. */
+++#define HAVE_RECVFROM 1
+++
+++/* Define to 1 if you have the send function. */
+++#define HAVE_SEND 1
+++
+++/* Define to 1 if you have the setsockopt function. */
+++#define HAVE_SETSOCKOPT 1
+++
+++/* Define to 1 if you have a working setsockopt SO_NONBLOCK function. */
+++/* #undef HAVE_SETSOCKOPT_SO_NONBLOCK */
+++
+++/* Define to 1 if you have the <signal.h> header file. */
+++#define HAVE_SIGNAL_H 1
+++
+++/* Define to 1 if sig_atomic_t is an available typedef. */
+++#define HAVE_SIG_ATOMIC_T 1
+++
+++/* Define to 1 if sig_atomic_t is already defined as volatile. */
+++/* #undef HAVE_SIG_ATOMIC_T_VOLATILE */
+++
+++/* Define to 1 if your struct sockaddr_in6 has sin6_scope_id. */
+++#define HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID 1
+++
+++/* Define to 1 if you have the socket function. */
+++#define HAVE_SOCKET 1
+++
+++/* Define to 1 if you have the <socket.h> header file. */
+++/* #undef HAVE_SOCKET_H */
+++
+++/* Define to 1 if you have the <stdbool.h> header file. */
+++#define HAVE_STDBOOL_H 1
+++
+++/* Define to 1 if you have the <stdint.h> header file. */
+++#define HAVE_STDINT_H 1
+++
+++/* Define to 1 if you have the <stdlib.h> header file. */
+++#define HAVE_STDLIB_H 1
+++
+++/* Define to 1 if you have the strcasecmp function. */
+++#define HAVE_STRCASECMP 1
+++
+++/* Define to 1 if you have the strcmpi function. */
+++/* #undef HAVE_STRCMPI */
+++
+++/* Define to 1 if you have the strdup function. */
+++#define HAVE_STRDUP 1
+++
+++/* Define to 1 if you have the stricmp function. */
+++/* #undef HAVE_STRICMP */
+++
+++/* Define to 1 if you have the <strings.h> header file. */
+++#define HAVE_STRINGS_H 1
+++
+++/* Define to 1 if you have the <string.h> header file. */
+++#define HAVE_STRING_H 1
+++
+++/* Define to 1 if you have the strncasecmp function. */
+++#define HAVE_STRNCASECMP 1
+++
+++/* Define to 1 if you have the strncmpi function. */
+++/* #undef HAVE_STRNCMPI */
+++
+++/* Define to 1 if you have the strnicmp function. */
+++/* #undef HAVE_STRNICMP */
+++
+++/* Define to 1 if you have the <stropts.h> header file. */
+++/* #undef HAVE_STROPTS_H */
+++
+++/* Define to 1 if you have struct addrinfo. */
+++#define HAVE_STRUCT_ADDRINFO 1
+++
+++/* Define to 1 if you have struct in6_addr. */
+++#define HAVE_STRUCT_IN6_ADDR 1
+++
+++/* Define to 1 if you have struct sockaddr_in6. */
+++#define HAVE_STRUCT_SOCKADDR_IN6 1
+++
+++/* if struct sockaddr_storage is defined */
+++#define HAVE_STRUCT_SOCKADDR_STORAGE 1
+++
+++/* Define to 1 if you have the timeval struct. */
+++#define HAVE_STRUCT_TIMEVAL 1
+++
+++/* Define to 1 if you have the <sys/ioctl.h> header file. */
+++#define HAVE_SYS_IOCTL_H 1
+++
+++/* Define to 1 if you have the <sys/param.h> header file. */
+++#define HAVE_SYS_PARAM_H 1
+++
+++/* Define to 1 if you have the <sys/select.h> header file. */
+++#define HAVE_SYS_SELECT_H 1
+++
+++/* Define to 1 if you have the <sys/socket.h> header file. */
+++#define HAVE_SYS_SOCKET_H 1
+++
+++/* Define to 1 if you have the <sys/stat.h> header file. */
+++#define HAVE_SYS_STAT_H 1
+++
+++/* Define to 1 if you have the <sys/time.h> header file. */
+++#define HAVE_SYS_TIME_H 1
+++
+++/* Define to 1 if you have the <sys/types.h> header file. */
+++#define HAVE_SYS_TYPES_H 1
+++
+++/* Define to 1 if you have the <sys/uio.h> header file. */
+++#define HAVE_SYS_UIO_H 1
+++
+++/* Define to 1 if you have the <time.h> header file. */
+++#define HAVE_TIME_H 1
+++
+++/* Define to 1 if you have the <unistd.h> header file. */
+++#define HAVE_UNISTD_H 1
+++
+++/* Define to 1 if you have the windows.h header file. */
+++/* #undef HAVE_WINDOWS_H */
+++
+++/* Define to 1 if you have the winsock2.h header file. */
+++/* #undef HAVE_WINSOCK2_H */
+++
+++/* Define to 1 if you have the winsock.h header file. */
+++/* #undef HAVE_WINSOCK_H */
+++
+++/* Define to 1 if you have the writev function. */
+++#define HAVE_WRITEV 1
+++
+++/* Define to 1 if you have the ws2tcpip.h header file. */
+++/* #undef HAVE_WS2TCPIP_H */
+++
+++/* Define if __system_property_get exists. */
+++/* #undef HAVE___SYSTEM_PROPERTY_GET */
+++
+++/* Define to the sub-directory where libtool stores uninstalled libraries. */
+++#define LT_OBJDIR ".libs/"
+++
+++/* Define to 1 if you need the malloc.h header file even with stdlib.h */
+++/* #undef NEED_MALLOC_H */
+++
+++/* Define to 1 if you need the memory.h header file even with stdlib.h */
+++/* #undef NEED_MEMORY_H */
+++
+++/* Define to 1 if _REENTRANT preprocessor symbol must be defined. */
+++/* #undef NEED_REENTRANT */
+++
+++/* Define to 1 if _THREAD_SAFE preprocessor symbol must be defined. */
+++/* #undef NEED_THREAD_SAFE */
+++
+++/* cpu-machine-OS */
+++#define OS "x86_64--netbsd"
+++
+++/* Name of package */
+++#define PACKAGE "c-ares"
+++
+++/* Define to the address where bug reports for this package should be sent. */
+++#define PACKAGE_BUGREPORT "c-ares mailing list: http://cool.haxx.se/mailman/listinfo/c-ares";
+++
+++/* Define to the full name of this package. */
+++#define PACKAGE_NAME "c-ares"
+++
+++/* Define to the full name and version of this package. */
+++#define PACKAGE_STRING "c-ares 1.13.0"
+++
+++/* Define to the one symbol short name of this package. */
+++#define PACKAGE_TARNAME "c-ares"
+++
+++/* Define to the home page for this package. */
+++#define PACKAGE_URL ""
+++
+++/* Define to the version of this package. */
+++#define PACKAGE_VERSION "1.13.0"
+++
+++/* a suitable file/device to read random data from */
+++#define RANDOM_FILE "/dev/urandom"
+++
+++/* Define to the type qualifier pointed by arg 5 for recvfrom. */
+++#define RECVFROM_QUAL_ARG5 
+++
+++/* Define to the type of arg 1 for recvfrom. */
+++#define RECVFROM_TYPE_ARG1 int
+++
+++/* Define to the type pointed by arg 2 for recvfrom. */
+++#define RECVFROM_TYPE_ARG2 void
+++
+++/* Define to 1 if the type pointed by arg 2 for recvfrom is void. */
+++#define RECVFROM_TYPE_ARG2_IS_VOID 1
+++
+++/* Define to the type of arg 3 for recvfrom. */
+++#define RECVFROM_TYPE_ARG3 size_t
+++
+++/* Define to the type of arg 4 for recvfrom. */
+++#define RECVFROM_TYPE_ARG4 int
+++
+++/* Define to the type pointed by arg 5 for recvfrom. */
+++#define RECVFROM_TYPE_ARG5 struct sockaddr
+++
+++/* Define to 1 if the type pointed by arg 5 for recvfrom is void. */
+++/* #undef RECVFROM_TYPE_ARG5_IS_VOID */
+++
+++/* Define to the type pointed by arg 6 for recvfrom. */
+++#define RECVFROM_TYPE_ARG6 socklen_t
+++
+++/* Define to 1 if the type pointed by arg 6 for recvfrom is void. */
+++/* #undef RECVFROM_TYPE_ARG6_IS_VOID */
+++
+++/* Define to the function return type for recvfrom. */
+++#define RECVFROM_TYPE_RETV ssize_t
+++
+++/* Define to the type of arg 1 for recv. */
+++#define RECV_TYPE_ARG1 int
+++
+++/* Define to the type of arg 2 for recv. */
+++#define RECV_TYPE_ARG2 void *
+++
+++/* Define to the type of arg 3 for recv. */
+++#define RECV_TYPE_ARG3 size_t
+++
+++/* Define to the type of arg 4 for recv. */
+++#define RECV_TYPE_ARG4 int
+++
+++/* Define to the function return type for recv. */
+++#define RECV_TYPE_RETV ssize_t
+++
+++/* Define as the return type of signal handlers (`int' or `void'). */
+++#define RETSIGTYPE void
+++
+++/* Define to the type qualifier of arg 2 for send. */
+++#define SEND_QUAL_ARG2 const
+++
+++/* Define to the type of arg 1 for send. */
+++#define SEND_TYPE_ARG1 int
+++
+++/* Define to the type of arg 2 for send. */
+++#define SEND_TYPE_ARG2 void *
+++
+++/* Define to the type of arg 3 for send. */
+++#define SEND_TYPE_ARG3 size_t
+++
+++/* Define to the type of arg 4 for send. */
+++#define SEND_TYPE_ARG4 int
+++
+++/* Define to the function return type for send. */
+++#define SEND_TYPE_RETV ssize_t
+++
+++/* Define to 1 if you have the ANSI C header files. */
+++#define STDC_HEADERS 1
+++
+++/* Define to 1 if you can safely include both <sys/time.h> and <time.h>. */
+++#define TIME_WITH_SYS_TIME 1
+++
+++/* Define to disable non-blocking sockets. */
+++/* #undef USE_BLOCKING_SOCKETS */
+++
+++/* Version number of package */
+++#define VERSION "1.13.0"
+++
+++/* Define to avoid automatic inclusion of winsock.h */
+++/* #undef WIN32_LEAN_AND_MEAN */
+++
+++/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
+++   significant byte first (like Motorola and SPARC, unlike Intel). */
+++#if defined AC_APPLE_UNIVERSAL_BUILD
+++# if defined __BIG_ENDIAN__
+++#  define WORDS_BIGENDIAN 1
+++# endif
+++#else
+++# ifndef WORDS_BIGENDIAN
+++/* #  undef WORDS_BIGENDIAN */
+++# endif
+++#endif
+++
+++/* Define to 1 if OS is AIX. */
+++#ifndef _ALL_SOURCE
+++/* #  undef _ALL_SOURCE */
+++#endif
+++
+++/* Enable large inode numbers on Mac OS X 10.5.  */
+++#ifndef _DARWIN_USE_64_BIT_INODE
+++# define _DARWIN_USE_64_BIT_INODE 1
+++#endif
+++
+++/* Number of bits in a file offset, on hosts where this is settable. */
+++/* #undef _FILE_OFFSET_BITS */
+++
+++/* Define for large files, on AIX-style hosts. */
+++/* #undef _LARGE_FILES */
+++
+++/* Define to empty if `const' does not conform to ANSI C. */
+++/* #undef const */
+++
+++/* Type to use in place of in_addr_t when system does not provide it. */
+++/* #undef in_addr_t */
+++
+++/* Define to `unsigned int' if <sys/types.h> does not define. */
+++/* #undef size_t */
diff --git a/bazel/patches/patch-third__party_zstd-jni_zstd-jni.BUILD b/bazel/patches/patch-third__party_zstd-jni_zstd-jni.BUILD
new file mode 100644
index 0000000000..10919b3b64
--- /dev/null
+++ b/bazel/patches/patch-third__party_zstd-jni_zstd-jni.BUILD
@@ -0,0 +1,12 @@
+$NetBSD$
+
+--- third_party/zstd-jni/zstd-jni.BUILD.orig	2023-11-28 16:52:47.128150508 +0000
++++ third_party/zstd-jni/zstd-jni.BUILD
+@@ -3,6 +3,7 @@ genrule(
+     srcs = select({
+         "@bazel_tools//src/conditions:darwin": ["@bazel_tools//tools/jdk:jni_md_header-darwin"],
+         "@bazel_tools//src/conditions:freebsd": ["@bazel_tools//tools/jdk:jni_md_header-freebsd"],
++        "@bazel_tools//src/conditions:netbsd": ["@bazel_tools//tools/jdk:jni_md_header-netbsd"],
+         "@bazel_tools//src/conditions:openbsd": ["@bazel_tools//tools/jdk:jni_md_header-openbsd"],
+         "@bazel_tools//src/conditions:windows": ["@bazel_tools//tools/jdk:jni_md_header-windows"],
+         "//conditions:default": ["@bazel_tools//tools/jdk:jni_md_header-linux"],
diff --git a/bazel/patches/patch-tools_cpp_BUILD.static.bsd b/bazel/patches/patch-tools_cpp_BUILD.static.bsd
new file mode 100644
index 0000000000..f8ed88a15d
--- /dev/null
+++ b/bazel/patches/patch-tools_cpp_BUILD.static.bsd
@@ -0,0 +1,57 @@
+$NetBSD$
+
+--- tools/cpp/BUILD.static.bsd.orig	2023-11-28 16:29:55.502670885 +0000
++++ tools/cpp/BUILD.static.bsd
+@@ -34,9 +34,11 @@ cc_toolchain_suite(
+     toolchains = {
+         "armeabi-v7a|compiler": ":cc-compiler-armeabi-v7a",
+         "freebsd|compiler": ":cc-compiler-freebsd",
++        "netbsd|compiler": ":cc-compiler-netbsd",
+         "openbsd|compiler": ":cc-compiler-openbsd",
+         "armeabi-v7a": ":cc-compiler-armeabi-v7a",
+         "freebsd": ":cc-compiler-freebsd",
++        "netbsd": ":cc-compiler-netbsd",
+         "openbsd": ":cc-compiler-openbsd",
+     },
+ )
+@@ -76,6 +78,40 @@ toolchain(
+ )
+ 
+ cc_toolchain(
++    name = "cc-compiler-netbsd",
++    all_files = ":empty",
++    ar_files = ":empty",
++    as_files = ":empty",
++    compiler_files = ":empty",
++    dwp_files = ":empty",
++    linker_files = ":empty",
++    objcopy_files = ":empty",
++    strip_files = ":empty",
++    supports_param_files = 0,
++    toolchain_config = ":local_netbsd",
++    toolchain_identifier = "local_netbsd",
++)
++
++cc_toolchain_config(
++    name = "local_netbsd",
++    cpu = "netbsd",
++)
++
++toolchain(
++    name = "cc-toolchain-netbsd",
++    exec_compatible_with = [
++        "@platforms//cpu:x86_64",
++        "@platforms//os:netbsd",
++    ],
++    target_compatible_with = [
++        "@platforms//cpu:x86_64",
++        "@platforms//os:netbsd",
++    ],
++    toolchain = ":cc-compiler-netbsd",
++    toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
++)
++
++cc_toolchain(
+     name = "cc-compiler-openbsd",
+     all_files = ":empty",
+     ar_files = ":empty",
diff --git a/bazel/patches/patch-tools_cpp_bsd__cc__toolchain__config.bzl b/bazel/patches/patch-tools_cpp_bsd__cc__toolchain__config.bzl
new file mode 100644
index 0000000000..3344869910
--- /dev/null
+++ b/bazel/patches/patch-tools_cpp_bsd__cc__toolchain__config.bzl
@@ -0,0 +1,49 @@
+$NetBSD$
+
+--- tools/cpp/bsd_cc_toolchain_config.bzl.orig	1979-12-31 15:00:00.000000000 +0000
++++ tools/cpp/bsd_cc_toolchain_config.bzl
+@@ -56,7 +56,7 @@ all_link_actions = [
+ 
+ def _impl(ctx):
+     cpu = ctx.attr.cpu
+-    is_bsd = cpu == "freebsd" or cpu == "openbsd"
++    is_bsd = cpu == "freebsd" or cpu == "netbsd" or cpu == "openbsd"
+     compiler = "compiler"
+     toolchain_identifier = "local_{}".format(cpu) if is_bsd else "stub_armeabi-v7a"
+     host_system_name = "local" if is_bsd else "armeabi-v7a"
+@@ -241,17 +241,32 @@ def _impl(ctx):
+     else:
+         features = [supports_dynamic_linker_feature, supports_pic_feature]
+ 
+-    if (is_bsd):
++    if is_bsd and not (cpu == "netbsd"):
+         cxx_builtin_include_directories = ["/usr/lib/clang", "/usr/local/include", "/usr/include"]
++    elif (cpu == "netbsd"):
++        cxx_builtin_include_directories = ["/usr/pkg/include", "/usr/include"]
+     else:
+         cxx_builtin_include_directories = []
+ 
+-    if is_bsd:
++    if is_bsd and not (cpu == "netbsd"):
++        tool_paths = [
++            tool_path(name = "ar", path = "/usr/bin/ar"),
++            tool_path(name = "cpp", path = "/usr/bin/cpp"),
++            tool_path(name = "dwp", path = "/usr/bin/dwp"),
++            tool_path(name = "gcc", path = "/usr/bin/cc"),
++            tool_path(name = "gcov", path = "/usr/bin/gcov"),
++            tool_path(name = "ld", path = "/usr/bin/ld"),
++            tool_path(name = "nm", path = "/usr/bin/nm"),
++            tool_path(name = "objcopy", path = "/usr/bin/objcopy"),
++            tool_path(name = "objdump", path = "/usr/bin/objdump"),
++            tool_path(name = "strip", path = "/usr/bin/strip"),
++        ]
++    elif (cpu == "netbsd"):
+         tool_paths = [
+             tool_path(name = "ar", path = "/usr/bin/ar"),
+             tool_path(name = "cpp", path = "/usr/bin/cpp"),
+             tool_path(name = "dwp", path = "/usr/bin/dwp"),
+-            tool_path(name = "gcc", path = "/usr/bin/clang"),
++            tool_path(name = "gcc", path = "/usr/bin/gcc"),
+             tool_path(name = "gcov", path = "/usr/bin/gcov"),
+             tool_path(name = "ld", path = "/usr/bin/ld"),
+             tool_path(name = "nm", path = "/usr/bin/nm"),
diff --git a/bazel/patches/patch-tools_cpp_cc__configure.bzl b/bazel/patches/patch-tools_cpp_cc__configure.bzl
new file mode 100644
index 0000000000..39c4fe26e1
--- /dev/null
+++ b/bazel/patches/patch-tools_cpp_cc__configure.bzl
@@ -0,0 +1,13 @@
+$NetBSD$
+
+--- tools/cpp/cc_configure.bzl.orig	2023-11-28 16:35:29.548083456 +0000
++++ tools/cpp/cc_configure.bzl
+@@ -102,7 +102,7 @@ def cc_autoconf_impl(repository_ctx, ove
+         repository_ctx.template("BUILD", paths["@bazel_tools//tools/cpp:BUILD.empty.tpl"], {
+             "%{cpu}": get_cpu_value(repository_ctx),
+         })
+-    elif cpu_value == "freebsd" or cpu_value == "openbsd":
++    elif cpu_value == "freebsd" or cpu_value == "netbsd" or cpu_value == "openbsd":
+         paths = resolve_labels(repository_ctx, [
+             "@bazel_tools//tools/cpp:BUILD.static.bsd",
+             "@bazel_tools//tools/cpp:bsd_cc_toolchain_config.bzl",
diff --git a/bazel/patches/patch-tools_cpp_lib__cc__configure.bzl b/bazel/patches/patch-tools_cpp_lib__cc__configure.bzl
new file mode 100644
index 0000000000..318db82f64
--- /dev/null
+++ b/bazel/patches/patch-tools_cpp_lib__cc__configure.bzl
@@ -0,0 +1,13 @@
+$NetBSD$
+
+--- tools/cpp/lib_cc_configure.bzl.orig	2023-11-28 16:25:10.088639234 +0000
++++ tools/cpp/lib_cc_configure.bzl
+@@ -192,6 +192,8 @@ def get_cpu_value(repository_ctx):
+         return "darwin" + ("_arm64" if arch == "aarch64" else "")
+     if os_name.find("freebsd") != -1:
+         return "freebsd"
++    if os_name.find("netbsd") != -1:
++        return "netbsd"
+     if os_name.find("openbsd") != -1:
+         return "openbsd"
+     if os_name.find("windows") != -1:
diff --git a/bazel/patches/patch-tools_cpp_unix__cc__configure.bzl b/bazel/patches/patch-tools_cpp_unix__cc__configure.bzl
new file mode 100644
index 0000000000..04aad3cd04
--- /dev/null
+++ b/bazel/patches/patch-tools_cpp_unix__cc__configure.bzl
@@ -0,0 +1,13 @@
+$NetBSD$
+
+--- tools/cpp/unix_cc_configure.bzl.orig	2023-11-28 16:29:01.387093015 +0000
++++ tools/cpp/unix_cc_configure.bzl
+@@ -344,7 +344,7 @@ def configure_unix_toolchain(repository_
+ 
+     repository_ctx.file("tools/cpp/empty.cc", "int main() {}")
+     darwin = cpu_value.startswith("darwin")
+-    bsd = cpu_value == "freebsd" or cpu_value == "openbsd"
++    bsd = cpu_value == "freebsd" or cpu_value == "netbsd" or cpu_value == "openbsd"
+ 
+     cc = find_cc(repository_ctx, overriden_tools)
+     is_clang = _is_clang(repository_ctx, cc)
diff --git a/bazel/patches/patch-tools_jdk_BUILD.java__tools b/bazel/patches/patch-tools_jdk_BUILD.java__tools
new file mode 100644
index 0000000000..d920f3bd89
--- /dev/null
+++ b/bazel/patches/patch-tools_jdk_BUILD.java__tools
@@ -0,0 +1,33 @@
+$NetBSD$
+
+--- tools/jdk/BUILD.java_tools.orig	1979-12-31 15:00:00.000000000 +0000
++++ tools/jdk/BUILD.java_tools
+@@ -130,6 +130,12 @@ config_setting(
+ )
+ 
+ config_setting(
++    name = "netbsd",
++    constraint_values = ["@platforms//os:netbsd"],
++    visibility = ["//visibility:public"],
++)
++
++config_setting(
+     name = "openbsd",
+     constraint_values = ["@platforms//os:openbsd"],
+     visibility = ["//visibility:public"],
+@@ -372,6 +378,7 @@ cc_binary(
+     copts = SUPRESSED_WARNINGS,
+     linkopts = select({
+         ":freebsd": ["-lm"],
++        ":netbsd": ["-lm"],
+         ":openbsd": ["-lm"],
+         "//conditions:default": [],
+     }),
+@@ -397,6 +404,7 @@ cc_binary(
+     copts = SUPRESSED_WARNINGS,
+     linkopts = select({
+         ":freebsd": ["-lm"],
++        ":netbsd": ["-lm"],
+         ":openbsd": ["-lm"],
+         "//conditions:default": [],
+     }),
diff --git a/bazel/patches/patch-tools_jdk_BUILD.tools b/bazel/patches/patch-tools_jdk_BUILD.tools
new file mode 100644
index 0000000000..5bdbbed963
--- /dev/null
+++ b/bazel/patches/patch-tools_jdk_BUILD.tools
@@ -0,0 +1,32 @@
+$NetBSD$
+
+--- tools/jdk/BUILD.tools.orig	2023-11-28 16:54:25.564264937 +0000
++++ tools/jdk/BUILD.tools
+@@ -106,6 +106,11 @@ java_runtime_files(
+ )
+ 
+ java_runtime_files(
++    name = "jni_md_header-netbsd",
++    srcs = ["include/netbsd/jni_md.h"],
++)
++
++java_runtime_files(
+     name = "jni_md_header-openbsd",
+     srcs = ["include/openbsd/jni_md.h"],
+ )
+@@ -127,6 +132,7 @@ cc_library(
+         "//src/conditions:linux_x86_64": [":jni_md_header-linux"],
+         "//src/conditions:darwin": [":jni_md_header-darwin"],
+         "//src/conditions:freebsd": [":jni_md_header-freebsd"],
++        "//src/conditions:netbsd": [":jni_md_header-netbsd"],
+         "//src/conditions:openbsd": [":jni_md_header-openbsd"],
+         "//src/conditions:windows": [":jni_md_header-windows"],
+         "//conditions:default": [],
+@@ -140,6 +146,7 @@ cc_library(
+         "//src/conditions:linux_x86_64": ["include/linux"],
+         "//src/conditions:darwin": ["include/darwin"],
+         "//src/conditions:freebsd": ["include/freebsd"],
++        "//src/conditions:netbsd": ["include/netbsd"],
+         "//src/conditions:openbsd": ["include/openbsd"],
+         "//src/conditions:windows": ["include/win32"],
+         "//conditions:default": [],
diff --git a/bazel/patches/patch-tools_jdk_jdk__build__file.bzl b/bazel/patches/patch-tools_jdk_jdk__build__file.bzl
new file mode 100644
index 0000000000..1f4e5c9328
--- /dev/null
+++ b/bazel/patches/patch-tools_jdk_jdk__build__file.bzl
@@ -0,0 +1,17 @@
+$NetBSD$
+
+--- tools/jdk/jdk_build_file.bzl.orig	2023-11-28 16:34:15.542839919 +0000
++++ tools/jdk/jdk_build_file.bzl
+@@ -49,6 +49,12 @@ filegroup(
+ )
+ 
+ filegroup(
++    name = "jni_md_header-netbsd",
++    srcs = ["include/netbsd/jni_md.h"],
++    deprecation = DEPRECATION_MESSAGE,
++)
++
++filegroup(
+     name = "jni_md_header-openbsd",
+     srcs = ["include/openbsd/jni_md.h"],
+     deprecation = DEPRECATION_MESSAGE,
diff --git a/bazel/patches/patch-tools_platforms_BUILD b/bazel/patches/patch-tools_platforms_BUILD
new file mode 100644
index 0000000000..1af9c7ef19
--- /dev/null
+++ b/bazel/patches/patch-tools_platforms_BUILD
@@ -0,0 +1,32 @@
+$NetBSD$
+
+--- tools/platforms/BUILD.orig	1979-12-31 15:00:00.000000000 +0000
++++ tools/platforms/BUILD
+@@ -84,6 +84,11 @@ alias(
+ )
+ 
+ alias(
++    name = "netbsd",
++    actual = "@platforms//os:netbsd",
++)
++
++alias(
+     name = "openbsd",
+     actual = "@platforms//os:openbsd",
+ )
+@@ -126,6 +131,7 @@ platform(
+     os_constraints = [
+         "@platforms//os:osx",
+         "@platforms//os:freebsd",
++        "@platforms//os:netbsd",
+         "@platforms//os:openbsd",
+         "@platforms//os:linux",
+         "@platforms//os:windows",
+@@ -149,6 +155,7 @@ platform(
+     os_constraints = [
+         "@platforms//os:osx",
+         "@platforms//os:freebsd",
++        "@platforms//os:netbsd",
+         "@platforms//os:openbsd",
+         "@platforms//os:linux",
+         "@platforms//os:windows",
diff --git a/bazel/patches/patch-tools_platforms_BUILD.tools b/bazel/patches/patch-tools_platforms_BUILD.tools
new file mode 100644
index 0000000000..1e419ed193
--- /dev/null
+++ b/bazel/patches/patch-tools_platforms_BUILD.tools
@@ -0,0 +1,32 @@
+$NetBSD$
+
+--- tools/platforms/BUILD.tools.orig	1979-12-31 15:00:00.000000000 +0000
++++ tools/platforms/BUILD.tools
+@@ -72,6 +72,11 @@ alias(
+ )
+ 
+ alias(
++    name = "netbsd",
++    actual = "@platforms//os:netbsd",
++)
++
++alias(
+     name = "openbsd",
+     actual = "@platforms//os:openbsd",
+ )
+@@ -114,6 +119,7 @@ platform(
+     os_constraints = [
+         "@platforms//os:osx",
+         "@platforms//os:freebsd",
++        "@platforms//os:netbsd",
+         "@platforms//os:openbsd",
+         "@platforms//os:linux",
+         "@platforms//os:windows",
+@@ -137,6 +143,7 @@ platform(
+     os_constraints = [
+         "@platforms//os:osx",
+         "@platforms//os:freebsd",
++        "@platforms//os:netbsd",
+         "@platforms//os:openbsd",
+         "@platforms//os:linux",
+         "@platforms//os:windows",



Home | Main Index | Thread Index | Old Index