0

I am using bazel to build my golang project. I want to use fips compliant crypto libraries.

I have made these changes in my WORKSPACE.bazel -

load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies", "go_download_sdk")

go_rules_dependencies()

go_register_toolchains(version = "1.14.8")

go_download_sdk(
    name = "go_sdk",
    sdks = {
       "linux_amd64": ("go1.14.15b4.linux-amd64.tar.gz", "82ba7297d26afcdade439de5621bdcb16e5261877f204aa60d03b5e07223a5c8"),
    },
    urls = ["https://go-boringcrypto.storage.googleapis.com/{}"],
)

This works fine and build is success on Ubuntu. But if I run it on MacOS, I get unsupported platform error.

Above boringcrypto sdk is not available for macos. So I want to remove this dependency in case platform is darwinamd64. How I can selectively add this dependency on the basis of OS? I want to add this sdk if OS is linux and not if OS is MacOS.

1 Answers1

1

config_setting and select can help you here, e.g.:

config_setting(
    name = "macos",
    constraint_values = [
        "@bazel_tools//platforms:osx",
    ],
    visibility = ["//visibility:public"],
)

cc_test(
    name = "test",
    srcs = ["test.cc"],
    copts = select({
        ":macos": ["/std:c++17"],
        "//conditions:default": ["-std=c++1z"],
    }),
)
Vertexwahn
  • 7,709
  • 6
  • 64
  • 90
  • I am using go_rules, specifically go_dowload_sdk. In go_download_sdk there is no attribute **copts** which I can use. I also tried go_wrap_sdk with attribute_files attribute still it did not work for me. – Aditya Maheshwari Dec 03 '21 at 07:11