github.com/0xKiwi/rules_go@v0.24.3/tests/core/cgo/BUILD.bazel (about)

     1  load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library", "go_test")
     2  load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_import", "cc_library")
     3  
     4  go_test(
     5      name = "opts_test",
     6      srcs = ["adder_test.go"],
     7      embed = [":opts"],
     8  )
     9  
    10  go_library(
    11      name = "opts",
    12      srcs = [
    13          "add.c",
    14          "add.cpp",
    15          "add.h",
    16          "adder.go",
    17      ] + select({
    18          "@io_bazel_rules_go//go/platform:darwin": [
    19              "add.m",
    20              "add.mm",
    21          ],
    22          "//conditions:default": [],
    23      }),
    24      cgo = True,
    25      copts = ["-DRULES_GO_C"],
    26      cppopts = ["-DRULES_GO_CPP"],
    27      cxxopts = ["-DRULES_GO_CXX"],
    28      importpath = "github.com/bazelbuild/rules_go/tests/core/cxx",
    29  )
    30  
    31  go_test(
    32      name = "dylib_test",
    33      srcs = ["dylib_test.go"],
    34      embed = [":dylib_client"],
    35      rundir = ".",
    36  )
    37  
    38  go_library(
    39      name = "dylib_client",
    40      srcs = ["dylib_client.go"],
    41      cdeps = select({
    42          "@io_bazel_rules_go//go/platform:darwin": [":darwin_imported_dylib"],
    43          "//conditions:default": [":linux_imported_dylib"],
    44          # TODO(jayconrod): Support windows, skip others.
    45      }),
    46      cgo = True,
    47      importpath = "github.com/bazelbuild/rules_go/tests/core/cgo/dylib",
    48  )
    49  
    50  cc_import(
    51      name = "darwin_imported_dylib",
    52      shared_library = "libimported.dylib",
    53      tags = ["manual"],
    54  )
    55  
    56  cc_binary(
    57      name = "libimported.dylib",
    58      srcs = ["imported.c"],
    59      linkopts = ["-install_name @rpath/libimported.dylib"],
    60      linkshared = True,
    61      tags = ["manual"],
    62  )
    63  
    64  cc_import(
    65      name = "linux_imported_dylib",
    66      shared_library = ":libimported.so",
    67      tags = ["manual"],
    68  )
    69  
    70  cc_binary(
    71      name = "libimported.so",
    72      srcs = ["imported.c"],
    73      linkshared = True,
    74      tags = ["manual"],
    75  )
    76  
    77  go_test(
    78      name = "versioned_dylib_test",
    79      srcs = ["dylib_test.go"],
    80      embed = [":versioned_dylib_client"],
    81      rundir = ".",
    82  )
    83  
    84  go_library(
    85      name = "versioned_dylib_client",
    86      srcs = ["dylib_client.go"],
    87      cdeps = select({
    88          # This test exists just for versioned `.so`s on Linux,
    89          # but we can reuse the above test's dylib so it passes on darwin,
    90          # where filename suffixes are not used for library version.
    91          "@io_bazel_rules_go//go/platform:darwin": [":darwin_imported_dylib"],
    92          "//conditions:default": [":linux_imported_versioned_dylib"],
    93          # TODO(jayconrod): Support windows, skip others.
    94      }),
    95      cgo = True,
    96      importpath = "github.com/bazelbuild/rules_go/tests/core/cgo/dylib",
    97  )
    98  
    99  cc_library(
   100      name = "linux_imported_versioned_dylib",
   101      srcs = [":libimported.so.2"],
   102      linkstatic = False,
   103      tags = ["manual"],
   104  )
   105  
   106  cc_binary(
   107      name = "libimported.so.2",
   108      srcs = ["imported.c"],
   109      linkshared = True,
   110      tags = ["manual"],
   111  )
   112  
   113  go_test(
   114      name = "cc_libs_test",
   115      srcs = [
   116          "cc_libs_darwin_test.go",
   117          "cc_libs_linux_test.go",
   118      ],
   119      data = [
   120          ":c_srcs",
   121          ":cc_deps",
   122          ":cc_srcs",
   123          ":pure",
   124      ],
   125      deps = ["//go/tools/bazel:go_default_library"],
   126  )
   127  
   128  go_binary(
   129      name = "pure",
   130      srcs = ["pure.go"],
   131      out = "pure_bin",
   132      cgo = True,
   133      pure = "on",
   134  )
   135  
   136  go_binary(
   137      name = "c_srcs",
   138      srcs = [
   139          "foo.c",
   140          "foo.go",
   141      ],
   142      out = "c_srcs_bin",
   143      cgo = True,
   144  )
   145  
   146  go_binary(
   147      name = "cc_srcs",
   148      srcs = [
   149          "bar.cc",
   150          "bar.go",
   151      ],
   152      out = "cc_srcs_bin",
   153      cgo = True,
   154  )
   155  
   156  go_binary(
   157      name = "cc_deps",
   158      srcs = ["bar.go"],
   159      out = "cc_deps_bin",
   160      cdeps = [":bar_dep"],
   161      cgo = True,
   162  )
   163  
   164  cc_library(
   165      name = "bar_dep",
   166      srcs = ["bar.cc"],
   167  )
   168  
   169  go_test(
   170      name = "race_test",
   171      srcs = [
   172          "race_off.c",
   173          "race_off.go",
   174          "race_on.c",
   175          "race_on.go",
   176          "race_test.go",
   177      ],
   178      cgo = True,
   179      race = "on",
   180  )
   181  
   182  go_test(
   183      name = "tag_test",
   184      srcs = ["tag_test.go"],
   185      data = [
   186          ":tag_cgo_bin",
   187          ":tag_pure_bin",
   188      ],
   189      rundir = ".",
   190      deps = ["//go/tools/bazel:go_default_library"],
   191  )
   192  
   193  go_binary(
   194      name = "tag_pure_bin",
   195      srcs = [
   196          "tag_pure.go",
   197          "tag_pure_err.c",
   198          "tag_pure_err.go",
   199      ],
   200      cgo = True,
   201      pure = "on",
   202  )
   203  
   204  go_binary(
   205      name = "tag_cgo_bin",
   206      srcs = [
   207          "tag_cgo.go",
   208          "tag_cgo_err.go",
   209      ],
   210      cgo = True,
   211      pure = "off",
   212  )
   213  
   214  go_test(
   215      name = "cgo_link_test",
   216      srcs = [
   217          "cgo_link_test.go",
   218          "cgo_ref.go",
   219      ],
   220      cdeps = [":cgo_link_dep"],
   221      cgo = True,
   222  )
   223  
   224  cc_library(
   225      name = "cgo_link_dep",
   226      srcs = ["cgo_link_dep.c"],
   227  )
   228  
   229  go_test(
   230      name = "split_import_test",
   231      srcs = [
   232          "split_import_i_test.go",
   233          "split_import_x_test.go",
   234      ],
   235      embed = [":split_import_a"],
   236      deps = [":split_import_b"],
   237  )
   238  
   239  go_library(
   240      name = "split_import_a",
   241      srcs = ["split_import_a.go"],
   242      importpath = "github.com/bazelbuild/rules_go/tests/core/cgo/split_import/a",
   243  )
   244  
   245  go_library(
   246      name = "split_import_b",
   247      srcs = ["split_import_b.go"],
   248      importpath = "github.com/bazelbuild/rules_go/tests/core/cgo/split_import/b",
   249      deps = [
   250          ":split_import_a",
   251          ":split_import_cgo",
   252      ],
   253  )
   254  
   255  go_library(
   256      name = "split_import_cgo",
   257      srcs = ["split_import_cgo.go"],
   258      cdeps = [":split_import_c"],
   259      cgo = True,
   260      importpath = "github.com/bazelbuild/rules_go/tests/core/cgo/split_import/cgo",
   261  )
   262  
   263  cc_library(
   264      name = "split_import_c",
   265      srcs = ["split_import_c.c"],
   266      hdrs = ["split_import_c.h"],
   267  )