fork/rules_rust

git clone https://git.julia.blue/fork/rules_rust

UebelAndreReplaced `crates_universe` rule with `crates_repository` (#1158)59fab4e7

rust-analyzer
2.7 KiB107 linesraw
1"""An openssl build file based on a snippet found in the github issue:
2https://github.com/bazelbuild/rules_foreign_cc/issues/337
3"""
4
5load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make", "configure_make_variant")
6
7# Read https://wiki.openssl.org/index.php/Compilation_and_Installation
8
9filegroup(
10    name = "all_srcs",
11    srcs = glob(["**"]),
12)
13
14CONFIGURE_OPTIONS = [
15    "no-comp",
16    "no-idea",
17    "no-weak-ssl-ciphers",
18    "no-shared",
19]
20
21LIB_NAME = "openssl"
22
23MAKE_TARGETS = [
24    "build_libs",
25    "install_dev",
26]
27
28config_setting(
29    name = "msvc_compiler",
30    flag_values = {
31        "@bazel_tools//tools/cpp:compiler": "msvc-cl",
32    },
33    visibility = ["//visibility:public"],
34)
35
36alias(
37    name = "openssl",
38    actual = select({
39        ":msvc_compiler": "openssl_msvc",
40        "//conditions:default": "openssl_default",
41    }),
42    visibility = ["//visibility:public"],
43)
44
45configure_make_variant(
46    name = "openssl_msvc",
47    build_data = [
48        "@nasm//:nasm",
49        "@perl//:perl",
50    ],
51    configure_command = "Configure",
52    configure_in_place = True,
53    configure_options = CONFIGURE_OPTIONS + [
54        "VC-WIN64A",
55        # Unset Microsoft Assembler (MASM) flags set by built-in MSVC toolchain,
56        # as NASM is unsed to build OpenSSL rather than MASM
57        "ASFLAGS=\" \"",
58    ],
59    configure_prefix = "$PERL",
60    env = {
61        # The Zi flag must be set otherwise OpenSSL fails to build due to missing .pdb files
62        "CFLAGS": "-Zi",
63        "PATH": "$$(dirname $(execpath @nasm//:nasm)):$$PATH",
64        "PERL": "$(execpath @perl//:perl)",
65    },
66    lib_name = LIB_NAME,
67    lib_source = ":all_srcs",
68    out_static_libs = [
69        "libssl.lib",
70        "libcrypto.lib",
71    ],
72    targets = MAKE_TARGETS,
73    toolchain = "@rules_foreign_cc//toolchains:preinstalled_nmake_toolchain",
74)
75
76configure_make(
77    name = "openssl_default",
78    configure_command = "config",
79    configure_in_place = True,
80    configure_options = CONFIGURE_OPTIONS,
81    env = select({
82        "@platforms//os:macos": {
83            "AR": "",
84            "PERL": "$$EXT_BUILD_ROOT$$/$(PERL)",
85        },
86        "//conditions:default": {
87            "PERL": "$$EXT_BUILD_ROOT$$/$(PERL)",
88        },
89    }),
90    lib_name = LIB_NAME,
91    lib_source = ":all_srcs",
92    # Note that for Linux builds, libssl must come before libcrypto on the linker command-line.
93    # As such, libssl must be listed before libcrypto
94    out_static_libs = [
95        "libssl.a",
96        "libcrypto.a",
97    ],
98    targets = MAKE_TARGETS,
99    toolchains = ["@rules_perl//:current_toolchain"],
100)
101
102filegroup(
103    name = "gen_dir",
104    srcs = [":openssl"],
105    output_group = "gen_dir",
106    visibility = ["//visibility:public"],
107)