|
21 | 21 | # 2.0 is the license version here, not the python version |
22 | 22 | license "Python-2.0" |
23 | 23 |
|
24 | | - unless windows_target? |
| 24 | + if !windows_target? |
25 | 25 | env = with_standard_compiler_flags(with_embedded_path) |
26 | 26 | python_configure_options = [ |
27 | 27 | "--without-readline", # Disables readline support |
|
66 | 66 | block do |
67 | 67 | FileUtils.rm_f(Dir.glob("#{install_dir}/embedded/lib/python#{major}.#{minor}/distutils/command/wininst-*.exe")) |
68 | 68 | end |
| 69 | + elsif fips_mode? |
| 70 | + ############################### |
| 71 | + # Setup openssl dependency... # |
| 72 | + ############################### |
| 73 | + |
| 74 | + # We must provide python with the same file hierarchy as |
| 75 | + # https://github.com/python/cpython-bin-deps/tree/openssl-bin-3.0/amd64 |
| 76 | + # but with our OpenSSL build instead. |
| 77 | + |
| 78 | + # This is not necessarily the version we built, but the version |
| 79 | + # the Python build system expects. |
| 80 | + openssl_version = "3.0.16.2" |
| 81 | + python_arch = "amd64" |
| 82 | + |
| 83 | + mkdir "externals\\openssl-bin-#{openssl_version}\\#{python_arch}\\include" |
| 84 | + # Copy the import library to have them point at our own built versions, regardless of |
| 85 | + # their names in usual python builds |
| 86 | + copy "#{install_dir}\\embedded3\\lib\\libcrypto.dll.a", "externals\\openssl-bin-#{openssl_version}\\#{python_arch}\\libcrypto.lib" |
| 87 | + copy "#{install_dir}\\embedded3\\lib\\libssl.dll.a", "externals\\openssl-bin-#{openssl_version}\\#{python_arch}\\libssl.lib" |
| 88 | + # Copy the actual DLLs, be sure to keep the same name since that's what the IMPLIBs expect |
| 89 | + copy "#{install_dir}\\embedded3\\bin\\libssl-3-x64.dll", "externals\\openssl-bin-#{openssl_version}\\#{python_arch}\\libssl-3.dll" |
| 90 | + # Create empty PDBs since python's build system require those to be present |
| 91 | + command "touch externals\\openssl-bin-#{openssl_version}\\#{python_arch}\\libssl-3.pdb" |
| 92 | + copy "#{install_dir}\\embedded3\\bin\\libcrypto-3-x64.dll", "externals\\openssl-bin-#{openssl_version}\\#{python_arch}\\libcrypto-3.dll" |
| 93 | + command "touch externals\\openssl-bin-#{openssl_version}\\#{python_arch}\\libcrypto-3.pdb" |
| 94 | + # And finally the headers: |
| 95 | + copy "#{install_dir}\\embedded3\\include\\openssl", "externals\\openssl-bin-#{openssl_version}\\#{python_arch}\\include\\" |
| 96 | + # Now build python itself... |
| 97 | + |
| 98 | + ############################### |
| 99 | + # Build Python... # |
| 100 | + ############################### |
| 101 | + # -e to enable external libraries. They won't be fetched if already |
| 102 | + # present, but the modules will be built nonetheless. |
| 103 | + command "PCbuild\\build.bat -e --pgo" |
| 104 | + # Install the built artifacts to their expected locations |
| 105 | + # --include-dev - include include/ and libs/ directories |
| 106 | + # --include-venv - necessary for ensurepip to work |
| 107 | + # --include-stable - adds python3.dll |
| 108 | + command "PCbuild\\#{python_arch}\\python.exe PC\\layout\\main.py --build PCbuild\\#{python_arch} --precompile --copy #{windows_safe_path(python_3_embedded)} --include-dev --include-venv --include-stable -vv" |
| 109 | + |
| 110 | + ############################### |
| 111 | + # Install build artifacts... # |
| 112 | + ############################### |
| 113 | + # We copied the OpenSSL libraries with the name python expects to keep the build happy |
| 114 | + # but at runtime, it will attempt to load the DLLs pointed at by the .dll.a generated by |
| 115 | + # the OpenSSL build, so we need to copy those files to the install directory. |
| 116 | + # The ones we copied for the build are now irrelevant |
| 117 | + openssl_arch = "x64" |
| 118 | + copy "#{install_dir}\\embedded3\\bin\\libcrypto-3-#{openssl_arch}.dll", "#{windows_safe_path(python_3_embedded)}\\DLLs" |
| 119 | + copy "#{install_dir}\\embedded3\\bin\\libssl-3-#{openssl_arch}.dll", "#{windows_safe_path(python_3_embedded)}\\DLLs" |
| 120 | + # We can also remove the DLLs that were put there by the python build since they won't be loaded anyway |
| 121 | + delete "#{windows_safe_path(python_3_embedded)}\\DLLs\\libcrypto-3.dll" |
| 122 | + delete "#{windows_safe_path(python_3_embedded)}\\DLLs\\libssl-3.dll" |
| 123 | + |
| 124 | + python = "#{windows_safe_path(python_3_embedded)}\\python.exe" |
| 125 | + command "#{python} -m ensurepip" |
69 | 126 | else |
70 | 127 | command_on_repo_root "bazelisk run -- @cpython//:install --destdir=#{python_3_embedded}" |
71 | 128 | end |
|
0 commit comments