# The code here was picked up from the `rules_foreign_cc` openssl example # https://github.com/bazelbuild/rules_foreign_cc/tree/0.5.1/examples/third_party/openssl load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make", "configure_make_variant") # Read https://wiki.openssl.org/index.php/Compilation_and_Installation filegroup( name = "all_srcs", srcs = glob(["**"]), ) CONFIGURE_OPTIONS = [ "no-comp", "no-idea", "no-weak-ssl-ciphers", "no-shared", ] LIB_NAME = "openssl" MAKE_TARGETS = [ "build_libs", "install_dev", ] config_setting( name = "msvc_compiler", flag_values = { "@bazel_tools//tools/cpp:compiler": "msvc-cl", }, visibility = ["//visibility:public"], ) alias( name = "openssl", actual = select({ ":msvc_compiler": "openssl_msvc", "//conditions:default": "openssl_default", }), visibility = ["//visibility:public"], ) configure_make_variant( name = "openssl_msvc", build_data = [ "@nasm_windows//:nasm", "@perl_windows//:perl", ], configure_command = "Configure", configure_in_place = True, configure_options = CONFIGURE_OPTIONS + [ "VC-WIN64A", # Unset Microsoft Assembler (MASM) flags set by built-in MSVC toolchain, # as NASM is unsed to build OpenSSL rather than MASM "ASFLAGS=\" \"", ], configure_prefix = "$PERL", env = { # The Zi flag must be set otherwise OpenSSL fails to build due to missing .pdb files "CFLAGS": "-Zi", "PATH": "$(dirname $(execpath @nasm_windows//:nasm)):$PATH", "PERL": "$(execpath @perl_windows//:perl)", }, lib_name = LIB_NAME, lib_source = ":all_srcs", out_static_libs = [ "libssl.lib", "libcrypto.lib", ], targets = MAKE_TARGETS, toolchain = "@rules_foreign_cc//toolchains:preinstalled_nmake_toolchain", ) configure_make( name = "openssl_default", configure_command = "config", configure_in_place = True, configure_options = CONFIGURE_OPTIONS, env = select({ "@platforms//os:macos": {"AR": ""}, "//conditions:default": {}, }), lib_name = LIB_NAME, lib_source = ":all_srcs", # Note that for Linux builds, libssl must come before libcrypto on the linker command-line. # As such, libssl must be listed before libcrypto out_static_libs = [ "libssl.a", "libcrypto.a", ], targets = MAKE_TARGETS, ) filegroup( name = "gen_dir", srcs = [":openssl"], output_group = "gen_dir", visibility = ["//visibility:public"], )