Skip to content

Commit 50a6606

Browse files
authored
Restore python bazel build while fixing FIPS issue (#43636)
### What does this PR do? It restores #43340 and fixes it by restoring the omnibus code path for fips mode Windows Agent. ### Motivation #incident-46365 https://gitlab.ddbuild.io/DataDog/datadog-agent/-/jobs/1261560018 I didn't look close enough at how the fips build is meant to work and the job didn't run on the PR. ### Describe how you validated your changes I've manually run the jobs that failed last time. - https://gitlab.ddbuild.io/DataDog/datadog-agent/-/jobs/1261820270 - https://gitlab.ddbuild.io/DataDog/datadog-agent/-/jobs/1261820269 ### Additional Notes Co-authored-by: alex.lopez <[email protected]>
1 parent e1ec2da commit 50a6606

File tree

5 files changed

+42
-17
lines changed

5 files changed

+42
-17
lines changed

deps/cpython.BUILD.bazel

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ python_externals = {
1111
"xz": "5.2.5",
1212
"zlib": "1.3.1",
1313
"libffi": "3.4.4",
14-
"openssl-bin": "3.0.16.2",
1514
"tcltk": "8.6.15.0",
1615
}
1716

@@ -27,6 +26,26 @@ python_externals = {
2726
for dep, version in python_externals.items()
2827
]
2928

29+
# This sets up OpenSSL files in a layout such as the Python build system for Windows expects
30+
copy_to_directory(
31+
name = "openssl-bin_win_dir",
32+
srcs = ["@openssl"],
33+
# TODO(team:agent-build): Single source of truth for dependency versions
34+
out = "openssl-bin-3.5.4/amd64",
35+
include_external_repositories = ["*openssl*"],
36+
# This reproduces the expected layout (libs at root, includes under `include`)
37+
root_paths = [
38+
"openssl/bin",
39+
"openssl/lib",
40+
"openssl",
41+
],
42+
replace_prefixes = {
43+
# We need to rename the .dll.a's into .lib files as the Python build expects
44+
"libcrypto.dll.a": "libcrypto.lib",
45+
"libssl.dll.a": "libssl.lib",
46+
},
47+
)
48+
3049
run_binary(
3150
name = "python_win",
3251
srcs = (
@@ -57,7 +76,7 @@ run_binary(
5776
"XZ_DIR": "$(location xz_win_dir)",
5877
"ZLIB_DIR": "$(location zlib_win_dir)",
5978
"LIBFFI_DIR": "$(location libffi_win_dir)",
60-
"OPENSSL_DIR": r"$(location openssl-bin_win_dir)\amd64",
79+
"OPENSSL_DIR": r"$(location openssl-bin_win_dir)",
6180
"TCLTK_DIR": r"$(location tcltk_win_dir)\amd64",
6281
"TCL_VERSION": python_externals["tcltk"],
6382
"MSBUILD": "$(location @visual_studio//:msbuild)",

deps/cpython/build_python.bat

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ echo "/p:libffiDir=%LIBFFI_DIR%" >> %response_file%
4242
echo "/p:opensslOutDir=%OPENSSL_DIR%" >> %response_file%
4343
echo "/p:tcltkdir=%TCLTK_DIR%" >> %response_file%
4444
echo "/p:TclVersion=%TCL_VERSION%" >> %response_file%
45+
:: We disable copying around of the OpenSSL libraries (as defined in openssl.props)
46+
:: This simplifies the requirements on the input files and their names and gives us more control
47+
echo "/p:SkipCopySSLDLL=1" >> %response_file%
4548

4649
:: -e flag would normally also fetch external dependencies, but we have a patch inhibiting that;
4750
:: the flag is still needed because otherwise modules depending on some of those external dependencies
@@ -52,6 +55,15 @@ if ERRORLEVEL 1 exit /b %ERRORLEVEL%
5255

5356
@echo on
5457

58+
:: Needed to avoid xcopy from failing when copying files out of this dir
59+
for %%F in (%OPENSSL_DIR%) do set OPENSSL_DIR=%%~fF
60+
61+
:: Copy OpenSSL files to where the layout script expects them.
62+
:: The Python build would do this itself when SkipCopySSLDLL is not set,
63+
:: since we enabled that, we need to now copy them manually
64+
xcopy /f %OPENSSL_DIR%*.lib %build_outdir%\
65+
xcopy /f %OPENSSL_DIR%*.dll %build_outdir%\
66+
5567
:: Create final layout from the build
5668
:: --include-dev - include include/ and libs/ directories
5769
:: --include-venv - necessary for ensurepip to work

deps/cpython/cpython.MODULE.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ python_src_deps = {
4646

4747
python_bin_deps = {
4848
"libffi": ("3.4.4", "681c0e6306b4bcb54ecce8305f67ca88ab03be922b6c4dcfd18240ad46e357d8"),
49-
"openssl-bin": ("3.0.16.2", "8686b76cbd4192143ed73bc60719efdb080bcdb8f887bdb7d66c5fecd2b6a36f"),
5049
"tcltk": ("8.6.15.0", "60adc5fc31c02347666198ffc74e5b6d0948f6765bb9034ae423a5a16c22a4e5"),
5150
}
5251

omnibus/config/software/openssl3.rb

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,10 @@
3333

3434
build do
3535
if !fips_mode?
36-
installation_dir = if windows? then python_3_embedded else "#{install_dir}/embedded" end
37-
command_on_repo_root "bazelisk run -- @openssl//:install --destdir=#{installation_dir}"
38-
if windows?
39-
block do
40-
# shutil generates temporary files during run install that are not removed afterwards.
41-
Dir.glob("#{installation_dir}/include/openssl/tmp*").each do |tmp_file|
42-
delete tmp_file
43-
end
44-
end
45-
else
46-
lib_extension = if linux_target? then ".so.#{version}" else ".#{version}.dylib" end
36+
# OpenSSL on Windows now gets installed as part of the Python install, so we don't need to do anything here
37+
if !windows?
38+
command_on_repo_root "bazelisk run -- @openssl//:install --destdir=#{install_dir}/embedded"
39+
lib_extension = if linux_target? then ".so" else ".dylib" end
4740
command_on_repo_root "bazelisk run -- //bazel/rules:replace_prefix --prefix #{install_dir}/embedded" \
4841
" #{install_dir}/embedded/lib/libssl#{lib_extension}" \
4942
" #{install_dir}/embedded/lib/libcrypto#{lib_extension}" \
@@ -124,4 +117,4 @@
124117
else
125118
end
126119
end
127-
end
120+
end

omnibus/config/software/python3.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
# 2.0 is the license version here, not the python version
2222
license "Python-2.0"
2323

24-
unless windows_target?
24+
if !windows_target?
2525
env = with_standard_compiler_flags(with_embedded_path)
2626
python_configure_options = [
2727
"--without-readline", # Disables readline support
@@ -66,7 +66,7 @@
6666
block do
6767
FileUtils.rm_f(Dir.glob("#{install_dir}/embedded/lib/python#{major}.#{minor}/distutils/command/wininst-*.exe"))
6868
end
69-
else
69+
elsif fips_mode?
7070
###############################
7171
# Setup openssl dependency... #
7272
###############################
@@ -123,6 +123,8 @@
123123

124124
python = "#{windows_safe_path(python_3_embedded)}\\python.exe"
125125
command "#{python} -m ensurepip"
126+
else
127+
command_on_repo_root "bazelisk run -- @cpython//:install --destdir=#{python_3_embedded}"
126128
end
127129
end
128130

0 commit comments

Comments
 (0)