Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
2ad5011
Make openssl build work on Windows
JSGette Nov 11, 2025
cf4159a
Buildify openssl.BUILD.bazel
JSGette Nov 11, 2025
f4ab990
Buildify bzip2.BUILD.bazel
JSGette Nov 11, 2025
ffe4fa1
Build openssl for Windows in CI
JSGette Nov 11, 2025
bb85147
Use pre-installed toolchains with rules_foreign_cc
JSGette Nov 12, 2025
fc3d5da
Fix the comment
JSGette Nov 12, 2025
0cb3cc5
Fix the comment #2
JSGette Nov 12, 2025
7b42a63
Replace PATH with Windows compliant value
JSGette Nov 12, 2025
ffc067a
Remove BAZEL_VS as we use MSYS2
JSGette Nov 12, 2025
41bd72b
Add informative hint
JSGette Nov 12, 2025
d7f95bc
Print stderr for Windows
JSGette Nov 12, 2025
fa0f646
Reduce parallelism on Windows
JSGette Nov 12, 2025
6516183
Use a single thread for openssl on Windows
JSGette Nov 12, 2025
2f3de73
Add windows related options to openssl
JSGette Nov 12, 2025
737c3a6
Add depend to ensure dependencies are built as well
JSGette Nov 12, 2025
65c9052
Try to only build openssl on Windows
JSGette Nov 12, 2025
e5b1acb
Use depend and build targets on Windows
JSGette Nov 12, 2025
3716a74
Force enable required macros
JSGette Nov 12, 2025
83ddff2
Use no-asm and targets from omnibus
JSGette Nov 12, 2025
99146f0
Remove no-asm
JSGette Nov 13, 2025
647bbad
Do not use cache for now
JSGette Nov 13, 2025
2f82fff
Use disk cache again
JSGette Nov 13, 2025
fcc4e57
Disable repo content cache explicitly
JSGette Nov 13, 2025
f25c8c5
Try to use bazel to build openssl in omnibus
JSGette Nov 14, 2025
fc4e862
Add missing load statements
JSGette Nov 14, 2025
50f2f9f
Fix openssl pkg_files target
JSGette Nov 14, 2025
b13e0e7
Expose configure_make outputs via filegroups
JSGette Nov 17, 2025
eac1eec
Finalize installation of openssl
JSGette Nov 17, 2025
326e121
Remove temporary files on Windows
JSGette Nov 17, 2025
7814133
Use lib64 for linux x86 to build openssl
JSGette Nov 17, 2025
abe8b11
Merge remote-tracking branch 'origin/main' into jsgette/bazel_openssl…
JSGette Nov 17, 2025
f976d58
Vendor rules_foreign_cc
JSGette Nov 18, 2025
b491a29
Add entry to DATADOG.md
JSGette Nov 18, 2025
0dce58b
Fix pkgconfig prefix
JSGette Nov 18, 2025
0870e5d
Fix pkgconfig prefix again
JSGette Nov 18, 2025
277ed22
Set --libdir for openssl build
JSGette Nov 18, 2025
8e94ade
Add replace for rules_foreign_cc
JSGette Nov 18, 2025
a309078
Build openssl with -O2
JSGette Nov 18, 2025
5613886
Use omnibus build for FIPS on Windows only
JSGette Nov 18, 2025
922db77
Use one sed command instead of 2
JSGette Nov 18, 2025
7559b7a
Merge remote-tracking branch 'origin/main' into jsgette/bazel_openssl…
JSGette Nov 18, 2025
de9d84e
Run replace_prefix on macos
JSGette Nov 18, 2025
e81fdc4
Fix replace_prefix to make it work on macos
JSGette Nov 19, 2025
59dc848
Fix openssl3.rb file
JSGette Nov 19, 2025
4dfb70c
Fix fips condition
JSGette Nov 19, 2025
21b8d3c
Fix lib_extension
JSGette Nov 19, 2025
16133d3
Fix prefix and config args for linux
JSGette Nov 19, 2025
88acf9a
Replace prefix entirely in pc files
JSGette Nov 19, 2025
accf77c
Increase stdouterr bytes
JSGette Nov 19, 2025
a92aa01
Use -id to change path to dylib
JSGette Nov 19, 2025
98cb1e8
Show stdout and stderr in bazel
JSGette Nov 19, 2025
e900b7f
Replace id and rpath on macos
JSGette Nov 19, 2025
3be942d
Replace id and rpath for deps too
JSGette Nov 19, 2025
2bd8472
Use zlib-dynamic in openssl
JSGette Nov 20, 2025
51fc089
Fix library paths properly
JSGette Nov 20, 2025
1638f3d
Fix Windows cleanup command
JSGette Nov 20, 2025
3842bc1
Fix lib extension on macos
JSGette Nov 20, 2025
cea7fe1
Expose dll.a files
JSGette Nov 20, 2025
2c15ccb
Add add_rpath for macos
JSGette Nov 20, 2025
86f3fe9
Expose dll.a files properly this time
JSGette Nov 21, 2025
45039dc
Use proper installation path on Windows
JSGette Nov 21, 2025
8de6c34
Merge remote-tracking branch 'origin/main' into jsgette/bazel_openssl…
JSGette Nov 21, 2025
a5884cd
Run mod tidy on lock file
JSGette Nov 21, 2025
eb8aa73
Tell buildifier to ignore includes
JSGette Nov 21, 2025
2a68626
Store dlls in bin
JSGette Nov 21, 2025
1a1c58c
Make `so_symlink` installation prefixes OS-specific
rdesgroppes Nov 21, 2025
0a030f4
Merge remote-tracking branch 'origin/regis.desgroppes/configure-os-sp…
JSGette Nov 21, 2025
bdea163
Do not set prefix in so_symlink
JSGette Nov 21, 2025
df26e32
Fix cleanup function
JSGette Nov 24, 2025
4b0a6e2
Use patch for rules_foreign_cc
JSGette Nov 25, 2025
e7b53a8
Remove mentioning from DATADOG.md
JSGette Nov 25, 2025
600e824
Merge remote-tracking branch 'origin/main' into jsgette/bazel_openssl…
JSGette Nov 25, 2025
020fdc2
Do not rename dll in so_symlink
JSGette Nov 25, 2025
75f73fb
Fix the patch for rules_foreign_cc
JSGette Nov 25, 2025
8d9cd02
Do not sign openssl.exe for non-fips
JSGette Nov 25, 2025
68f13b1
Simplify conditions
JSGette Nov 25, 2025
527deb5
Fix ruby syntax errors
JSGette Nov 26, 2025
4126a2e
Introduce MSYS2_PATH attribute
JSGette Nov 26, 2025
5c319ac
Remove commented lines
JSGette Nov 26, 2025
bbba19b
Address review comments
JSGette Nov 26, 2025
03a486f
Restore missing end
JSGette Nov 27, 2025
6ad31f9
Merge remote-tracking branch 'origin/main' into jsgette/bazel_openssl…
JSGette Nov 27, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ common:macos --strategy=sandboxed
# Windows config -------------------------------------------------------------------------------------------------------
common:windows --strategy=standalone # Valid values are: [dynamic_worker, standalone, dynamic, remote, worker, local]
# For whatever reason if convenience symlinks are present, the build fails on Windows.
# Disabling them for now.
common:windows --noexperimental_convenience_symlinks
# shell_executable doesn't affect action keys. It can be both an advantage and a disadvantage.
# For instance, if we need to have some special behavior in bash we can add it, however, in some cases
# it may lead to cache poisoning.
common:windows --noexperimental_convenience_symlinks --shell_executable=C:/tools/msys64/usr/bin/bash.exe

# Remote cache config --------------------------------------------------------------------------------------------------
# datadog-agent virtually isolates caching instance from its parent (which is remote-caching).
Expand All @@ -35,6 +37,7 @@ common:cache --remote_timeout=60
# CI config ------------------------------------------------------------------------------------------------------------
common:ci --config=cache
common:ci --test_output=errors # Print test setup errors to the job output instead of only capturing them in test.log
common --experimental_ui_max_stdouterr_bytes=1073741819

# Local development options --------------------------------------------------------------------------------------------
try-import %workspace%/user.bazelrc
2 changes: 1 addition & 1 deletion .gitlab/bazel/build-deps.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ bazel:build-deps:windows-amd64:
variables:
POWERSHELL_SCRIPT: |-
[Console]::WriteLine("🟡 TODO(regis): compilation errors remain - limiting to a working subset for the time being")
bazel build '@zlib//...' '@libffi//:ffi' '@xz//...' '@cpython//...' --platforms=//bazel/platforms:windows_x86_64
bazel build '@zlib//...' '@libffi//:ffi' '@xz//...' '@cpython//...' '@openssl//...' --platforms=//bazel/platforms:windows_x86_64
# bazel build @bzip2//...
13 changes: 13 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,23 @@ register_toolchains("@pythons_hub//:all")
#########################

# Make our 3rd parties depencency repositories known
# bazel mod tidy command adds a new line between includes.
# buildifier eliminates them. If we treat mod tidy as a code formatter
# for MODULE.bazel, we need to leave-alone the includes so that buildifier
# doesn't fail nor re-format them.
# buildifier: leave-alone
include("//deps:repos.MODULE.bazel")

# buildifier: leave-alone
include("//deps/acl:acl.MODULE.bazel")

# buildifier: leave-alone
include("//deps/cpython:cpython.MODULE.bazel")

# buildifier: leave-alone
include("//deps/openssl3:openssl3.MODULE.bazel")

# buildifier: leave-alone
include("//deps/libpcap:libpcap.MODULE.bazel")

# This enables cross-compilation for macOS x86_64 on Apple Silicon.
Expand Down
79 changes: 79 additions & 0 deletions bazel/patches/rules_foreign_cc/0000-expose-pc-files.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
diff --git a/foreign_cc/private/framework.bzl b/foreign_cc/private/framework.bzl
index 6bf25d9..a081d31 100644
--- a/foreign_cc/private/framework.bzl
+++ b/foreign_cc/private/framework.bzl
@@ -202,6 +202,10 @@ CC_EXTERNAL_RULE_ATTRIBUTES = {
),
mandatory = False,
),
+ "out_pc_dir": attr.string(
+ doc = "Optional name of the output directory with the pkgconfig files",
+ mandatory = False,
+ ),
"postfix_script": attr.string(
doc = "Optional part of the shell script to be added after the make commands",
mandatory = False,
@@ -592,7 +596,8 @@ def cc_external_rule_impl(ctx, attrs):
outputs.out_binary_files +
outputs.libraries.static_libraries +
outputs.libraries.shared_libraries +
- [outputs.out_include_dir] if outputs.out_include_dir else []
+ ([outputs.out_include_dir] if outputs.out_include_dir else []) +
+ ([outputs.out_pc_dir] if outputs.out_pc_dir else [])
)
output_groups = _declare_output_groups(installdir_copy.file, output_groups)
wrapped_files = [
@@ -842,6 +847,7 @@ _Outputs = provider(
out_include_dir = "Directory with header files (relative to install directory)",
out_binary_files = "Binary files, which will be created by the action",
libraries = "Library files, which will be created by the action",
+ out_pc_dir = "Directory with pkgconfig files (relative to install directory)",
declared_outputs = "All output files and directories of the action",
),
)
@@ -854,6 +860,7 @@ def _define_outputs(ctx, attrs, lib_name):
attr_out_data_files = attrs.out_data_files
attr_shared_libs = attrs.out_shared_libs
attr_static_libs = attrs.out_static_libs
+ attr_out_pc_dir = attrs.out_pc_dir

static_libraries = []
if not attr_headers_only:
@@ -875,6 +882,11 @@ def _define_outputs(ctx, attrs, lib_name):
else:
out_include_dir = ""

+ if attrs.out_pc_dir and (attr_shared_libs or attr_static_libs):
+ out_pc_dir = ctx.actions.declare_directory(lib_name + "/" + attr_out_pc_dir.lstrip("/"))
+ else:
+ out_pc_dir = ""
+
out_data_dirs = []
for dir in attr_out_data_dirs:
out_data_dirs.append(ctx.actions.declare_directory(lib_name + "/" + dir.lstrip("/")))
@@ -893,11 +905,13 @@ def _define_outputs(ctx, attrs, lib_name):
declared_outputs += out_data_dirs + out_binary_files + out_data_files
declared_outputs += libraries.static_libraries
declared_outputs += libraries.shared_libraries + libraries.interface_libraries
+ declared_outputs += [out_pc_dir] if out_pc_dir else []

return _Outputs(
out_include_dir = out_include_dir,
out_binary_files = out_binary_files,
libraries = libraries,
+ out_pc_dir = out_pc_dir,
declared_outputs = declared_outputs,
)

diff --git a/foreign_cc/providers.bzl b/foreign_cc/providers.bzl
index 2de172f..3f49b7d 100644
--- a/foreign_cc/providers.bzl
+++ b/foreign_cc/providers.bzl
@@ -20,6 +20,7 @@ Instances of ForeignCcArtifactInfo are encapsulated in a depset [ForeignCcDepsIn
"dll_dir_name": "DLL directory, relative to install directory",
"gen_dir": "Install directory",
"include_dir_name": "Include directory, relative to install directory",
+ "pc_dir_name": "Pkgconfig directory, relative to install directory",
"lib_dir_name": "Lib directory, relative to install directory",
},
)
20 changes: 18 additions & 2 deletions bazel/rules/replace_prefix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,26 @@ for f in "$@"; do
${PATCHELF} --set-rpath "$PREFIX"/lib "$f"
;;
*.dylib)
install_name_tool -add_rpath "$PREFIX/lib" "$f"
install_name_tool -add_rpath "$PREFIX/lib" "$f" 2>/dev/null || true
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bazel is way more relaxed in comparison to omnibus, as it doesn't set rpath at all. We also need to replace all bazel-related paths to dependency dylibs to make it work with pkg_install

# Get the old install name/ID
dylib_name=$(basename "$f")
new_id="$PREFIX/lib/$dylib_name"

# Change the dylib's own ID
install_name_tool -id "$new_id" "$f"

# Update all dependency paths that point to sandbox locations
otool -L "$f" | tail -n +2 | awk '{print $1}' | while read -r dep; do
if [[ "$dep" == *"sandbox"* ]] || [[ "$dep" == *"bazel-out"* ]]; then
dep_name=$(basename "$dep")
new_dep="$PREFIX/lib/$dep_name"
install_name_tool -change "$dep" "$new_dep" "$f" 2>/dev/null || true
install_name_tool -add_rpath "$PREFIX/lib" "$dep" 2>/dev/null || true
fi
done
;;
*.pc)
sed -ibak "s|##PREFIX##|$PREFIX|" "$f" && rm -f "${f}bak"
sed -ibak -e "s|^prefix=.*|prefix=$PREFIX|" -e "s|##PREFIX##|$PREFIX|" -e "s|\${EXT_BUILD_DEPS}|$PREFIX|" "$f" && rm -f "${f}bak"
;;
*)
if file "$f" | grep -q ELF; then
Expand Down
20 changes: 17 additions & 3 deletions bazel/rules/so_symlink.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@ _SPECS = [
def _gen_targets(base_name, src, libname, version, spec):
name = "{}_{}".format(base_name, spec.os)
platform = "@platforms//os:{}".format(spec.os)

# Windows: no symlinks, no renaming - just copy the DLL as-is
if spec.os == "windows":
pkg_files(
name = name,
srcs = [src],
prefix = spec.prefix,
target_compatible_with = [platform],
)
return platform, ":{}".format(name)

# Unix: create symlink chain with versioning
target = spec.format.format(libname, ".{}".format(version))
targets = ["{}_real_name".format(name)]
pkg_files(
Expand Down Expand Up @@ -37,20 +49,22 @@ def _gen_targets(base_name, src, libname, version, spec):
return platform, ":{}".format(name)

def so_symlink(name, src, libname, version):
"""Creates shared library symlink chain following Unix conventions.
"""Creates shared library packaging appropriate for each platform.

Generates the common multilevel symlink hierarchy for shared libraries, for reference:
Unix (Linux/macOS): Generates the common multilevel symlink hierarchy for shared libraries:
- `real name`: actual file with full version (e.g., libreadline.so.3.0 / libreadline.3.0.dylib)
- `soname`: major version symlink, for runtime ABI compatibility (e.g., libreadline.so.3 / libreadline.3.dylib)
- `linker name`: unversioned symlink, for development/linking (e.g., libreadline.so / libreadline.dylib)

Windows: Simply copies the DLL to bin/ without renaming or creating symlinks.

See: `Program Library HOWTO` by David Wheeler, https://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html

Args:
name: Name of the generated pkg_filegroup
src: Label of the cc_shared_library to package
libname: Library name without extension (e.g., "libreadline")
version: Full version string (e.g., "3.0")
version: Full version string (e.g., "3.0", ignored on Windows)
"""
native.alias(
name = name,
Expand Down
5 changes: 4 additions & 1 deletion bazel/toolchains/mingw/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
load("@rules_cc//cc:defs.bzl", "cc_toolchain")
load("//bazel/toolchains/mingw:toolchain.bzl", "mingw_cc_toolchain_config")

MSYS2_PATH = "C:/tools/msys64"

mingw_cc_toolchain_config(
name = "mingw-cc-toolchain-config",
GCC_VERSION = "14.2.0",
MINGW_PATH = "C:/tools/msys64/mingw64",
MINGW_PATH = MSYS2_PATH + "/mingw64",
MSYS2_PATH = MSYS2_PATH,
)

filegroup(
Expand Down
5 changes: 4 additions & 1 deletion bazel/toolchains/mingw/toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ def _impl(ctx):
flag_groups = [
flag_group(
flags = [
"-no-canonical-prefixes",
"-fno-canonical-system-headers",
"-Wno-builtin-macro-redefined",
"-D__DATE__=\"redacted\"",
"-D__TIMESTAMP__=\"redacted\"",
Expand All @@ -78,7 +80,7 @@ def _impl(ctx):
ACTION_NAMES.cpp_link_static_library,
],
env_entries = [
env_entry("PATH", "{}/bin".format(ctx.attr.MINGW_PATH)),
env_entry("PATH", "{}/usr/bin;{}/bin".format(ctx.attr.MSYS2_PATH, ctx.attr.MINGW_PATH)),
],
),
],
Expand Down Expand Up @@ -202,6 +204,7 @@ def _impl(ctx):
mingw_cc_toolchain_config = rule(
implementation = _impl,
attrs = {
"MSYS2_PATH": attr.string(mandatory = True),
"MINGW_PATH": attr.string(mandatory = True),
"GCC_VERSION": attr.string(mandatory = True),
},
Expand Down
4 changes: 2 additions & 2 deletions deps/bzip2.BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ cc_library(
"-O3",
],
"@platforms//os:windows": [
"/O2",
"-O2",
],
},
no_match_error = "No target platform detected",
Expand All @@ -108,7 +108,7 @@ cc_library(
"@platforms//os:windows": ["_CRT_NONSTDC_NO_WARNINGS"],
"//conditions:default": [],
}),
includes = ['.'],
includes = ["."],
visibility = ["//visibility:public"],
)

Expand Down
Loading