• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2009-2021, Google LLC
2# All rights reserved.
3#
4# Use of this source code is governed by a BSD-style
5# license that can be found in the LICENSE file or at
6# https://developers.google.com/open-source/licenses/bsd
7
8load("@rules_pkg//pkg:mappings.bzl", "pkg_files", "strip_prefix")
9load(
10    "//upb/bazel:build_defs.bzl",
11    "make_shell_script",
12)
13load(
14    ":build_defs.bzl",
15    "staleness_test",
16)
17
18licenses(["notice"])
19
20exports_files(["staleness_test.py"])
21
22py_library(
23    name = "staleness_test_lib",
24    testonly = 1,
25    srcs = ["staleness_test_lib.py"],
26    # This is public only for use by the staleness_test() macro. Please do not
27    # depend on this target directly.
28    visibility = ["//visibility:public"],
29)
30
31py_binary(
32    name = "make_cmakelists",
33    srcs = ["make_cmakelists.py"],
34)
35
36genrule(
37    name = "gen_cmakelists",
38    srcs = [
39        "//upb:BUILD",
40    ],
41    outs = ["generated-in/CMakeLists.txt"],
42    cmd = "$(location :make_cmakelists) " +
43          "$(location //upb:BUILD) $@",
44    tools = [":make_cmakelists"],
45)
46
47genrule(
48    name = "copy_protos",
49    srcs = [
50        "//src/google/protobuf:descriptor_upb_c_proto",
51        "//src/google/protobuf:descriptor_upb_minitable_proto",
52    ],
53    outs = [
54        "generated-in/google/protobuf/descriptor.upb.h",
55        "generated-in/google/protobuf/descriptor.upb_minitable.c",
56        "generated-in/google/protobuf/descriptor.upb_minitable.h",
57    ],
58    cmd = "cp $(SRCS) $(@D)/generated-in/google/protobuf",
59)
60
61staleness_test(
62    name = "test_generated_files",
63    outs = [
64        "CMakeLists.txt",
65        "google/protobuf/descriptor.upb.h",
66        "google/protobuf/descriptor.upb_minitable.c",
67        "google/protobuf/descriptor.upb_minitable.h",
68    ],
69    generated_pattern = "generated-in/%s",
70    tags = ["manual"],
71)
72
73# Test the CMake build #########################################################
74
75make_shell_script(
76    name = "gen_run_cmake_build",
77    out = "run_cmake_build.sh",
78    contents = "set -ex\n" +
79               "cd $(dirname $1) && cp -r . .. && cd ../..\n" +
80               "mkdir build && cd build && cmake ../cmake && make -j8 && make test",
81)
82
83sh_test(
84    name = "cmake_build",
85    srcs = ["run_cmake_build.sh"],
86    args = ["$(location :gen_cmakelists)"],
87    data = [
88        ":copy_protos",
89        ":gen_cmakelists",
90        "//third_party/utf8_range:utf8_range_srcs",
91        "//upb:source_files",
92        "//upb/base:source_files",
93        "//upb/hash:source_files",
94        "//upb/lex:source_files",
95        "//upb/mem:source_files",
96        "//upb/message:source_files",
97        "//upb/mini_descriptor:source_files",
98        "//upb/mini_table:source_files",
99        "//upb/port:source_files",
100        "//upb/reflection:source_files",
101        "//upb/text:source_files",
102        "//upb/wire:source_files",
103    ],
104    target_compatible_with = select({
105        "@platforms//os:windows": ["@platforms//:incompatible"],
106        "//conditions:default": [],
107    }),
108    deps = ["@bazel_tools//tools/bash/runfiles"],
109)
110
111pkg_files(
112    name = "upb_cmake_dist",
113    srcs = [
114        ":copy_protos",
115        ":gen_cmakelists",
116        "//third_party/utf8_range:utf8_range_srcs",
117        "//upb:source_files",
118        "//upb/base:source_files",
119        "//upb/hash:source_files",
120        "//upb/lex:source_files",
121        "//upb/mem:source_files",
122        "//upb/message:source_files",
123        "//upb/mini_descriptor:source_files",
124        "//upb/mini_table:source_files",
125        "//upb/port:source_files",
126        "//upb/reflection:source_files",
127        "//upb/text:source_files",
128        "//upb/wire:source_files",
129    ],
130    strip_prefix = strip_prefix.from_root(""),
131    visibility = ["//rust:__pkg__"],
132)
133