From 20d849a5e03945a5c764f3ffa98a6525378274e9 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Tue, 7 May 2019 11:30:28 -0700 Subject: Fixes for Bazel 0.25. Disabled the conformance tests for now because I didn't push the necessary changes to the protobuf repo yet. --- BUILD | 78 +++++++++++++++++++++++++++++----------------------------- WORKSPACE | 15 +++++++---- build_defs.bzl | 16 ++++++------ 3 files changed, 58 insertions(+), 51 deletions(-) diff --git a/BUILD b/BUILD index 5b1dd33..629287c 100644 --- a/BUILD +++ b/BUILD @@ -350,45 +350,45 @@ cc_test( copts = CPPOPTS, ) -upb_proto_library( - name = "conformance_proto_upb", - deps = ["@com_google_protobuf//:conformance_proto"], -) - -upb_proto_library( - name = "test_messages_proto3_proto_upb", - deps = ["@com_google_protobuf//:test_messages_proto3_proto"], -) - -cc_binary( - name = "conformance_upb", - srcs = [ - "tests/conformance_upb.c", - ], - copts = COPTS + ["-Ibazel-out/k8-fastbuild/bin"], - deps = [ - ":conformance_proto_upb", - ":test_messages_proto3_proto_upb", - ":upb", - ], -) - -make_shell_script( - name = "gen_test_conformance_upb", - out = "test_conformance_upb.sh", - contents = "$(rlocation com_google_protobuf/conformance_test_runner) $(rlocation upb/conformance_upb)", -) - -sh_test( - name = "test_conformance_upb", - srcs = ["test_conformance_upb.sh"], - data = [ - "tests/conformance_upb_failures.txt", - ":conformance_upb", - "@bazel_tools//tools/bash/runfiles", - "@com_google_protobuf//:conformance_test_runner", - ], -) +#upb_proto_library( +# name = "conformance_proto_upb", +# deps = ["@com_google_protobuf//:conformance_proto"], +#) + +#upb_proto_library( +# name = "test_messages_proto3_proto_upb", +# deps = ["@com_google_protobuf//:test_messages_proto3_proto"], +#) + +#cc_binary( +# name = "conformance_upb", +# srcs = [ +# "tests/conformance_upb.c", +# ], +# copts = COPTS + ["-Ibazel-out/k8-fastbuild/bin"], +# deps = [ +# ":conformance_proto_upb", +# ":test_messages_proto3_proto_upb", +# ":upb", +# ], +#) +# +#make_shell_script( +# name = "gen_test_conformance_upb", +# out = "test_conformance_upb.sh", +# contents = "$(rlocation com_google_protobuf/conformance_test_runner) $(rlocation upb/conformance_upb)", +#) +# +#sh_test( +# name = "test_conformance_upb", +# srcs = ["test_conformance_upb.sh"], +# data = [ +# "tests/conformance_upb_failures.txt", +# ":conformance_upb", +# "@bazel_tools//tools/bash/runfiles", +# "@com_google_protobuf//:conformance_test_runner", +# ], +#) # Amalgamation ################################################################# diff --git a/WORKSPACE b/WORKSPACE index d49b894..ff89757 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -17,11 +17,16 @@ http_archive( git_repository( name = "com_google_protobuf", - commit = "25feb59620627b673df76813dfd66e3f565765e7", - #sha256 = "d7a221b3d4fb4f05b7473795ccea9e05dab3b8721f6286a95fffbffc2d926f8b", - remote = "https://github.com/haberman/protobuf.git", - shallow_since = "1541281400 -0700" - #tag = "conformance-build-tag", + commit = "ec1a70913e5793a7d0a7b5fbf7e0e4f75409dd41", + remote = "https://github.com/protocolbuffers/protobuf.git", +) + +http_archive( + name = "zlib", + build_file = "@com_google_protobuf//:third_party/zlib.BUILD", + sha256 = "c3e5e9fdd5004dcb542feda5ee4f0ff0744628baf8ed2dd5d66f8ca1197cb1a1", + strip_prefix = "zlib-1.2.11", + urls = ["https://zlib.net/zlib-1.2.11.tar.gz"], ) git_repository( diff --git a/build_defs.bzl b/build_defs.bzl index 9deb336..f24cff5 100644 --- a/build_defs.bzl +++ b/build_defs.bzl @@ -1,3 +1,7 @@ + +load("@bazel_skylib//lib:paths.bzl", "paths") +load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain") + _shell_find_runfiles = """ # --- begin runfiles.bash initialization --- # Copy-pasted from Bazel's Bash runfiles library (tools/bash/runfiles/runfiles.bash). @@ -23,10 +27,6 @@ _shell_find_runfiles = """ # --- end runfiles.bash initialization --- """ -load("@bazel_skylib//lib:paths.bzl", "paths") -load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain") -load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "CPP_LINK_STATIC_LIBRARY_ACTION_NAME") - def _librule(name): return name + "_lib" @@ -286,15 +286,17 @@ def cc_library_func(ctx, hdrs, srcs, deps): unsupported_features = ctx.disabled_features, ) compilation_info = cc_common.compile( - ctx = ctx, + actions = ctx.actions, feature_configuration = feature_configuration, cc_toolchain = toolchain, + name = "upb_lib", srcs = srcs, - hdrs = hdrs, + public_hdrs = hdrs, compilation_contexts = compilation_contexts, ) linking_info = cc_common.link( - ctx = ctx, + actions = ctx.actions, + name = "upb_lib", feature_configuration = feature_configuration, cc_toolchain = toolchain, cc_compilation_outputs = compilation_info.cc_compilation_outputs, -- cgit v1.2.3 From 6c1b78f09553ca14b20fcab070b1f730260838ed Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Tue, 7 May 2019 14:38:08 -0700 Subject: Update Skylib and update to newer Sandwich API. --- WORKSPACE | 7 +++---- build_defs.bzl | 10 +++++----- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/WORKSPACE b/WORKSPACE index ff89757..254d113 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -45,8 +45,7 @@ http_archive( ) http_archive( - name = "bazel_skylib", - sha256 = "bbccf674aa441c266df9894182d80de104cabd19be98be002f6d478aaa31574d", - strip_prefix = "bazel-skylib-2169ae1c374aab4a09aa90e65efe1a3aad4e279b", - urls = ["https://github.com/bazelbuild/bazel-skylib/archive/2169ae1c374aab4a09aa90e65efe1a3aad4e279b.tar.gz"], + name = "bazel_skylib", + strip_prefix = "bazel-skylib-master", + urls = ["https://github.com/bazelbuild/bazel-skylib/archive/master.tar.gz"], ) diff --git a/build_defs.bzl b/build_defs.bzl index f24cff5..3e69680 100644 --- a/build_defs.bzl +++ b/build_defs.bzl @@ -285,7 +285,7 @@ def cc_library_func(ctx, hdrs, srcs, deps): requested_features = ctx.features, unsupported_features = ctx.disabled_features, ) - compilation_info = cc_common.compile( + (compilation_context, compilation_outputs) = cc_common.compile( actions = ctx.actions, feature_configuration = feature_configuration, cc_toolchain = toolchain, @@ -294,18 +294,18 @@ def cc_library_func(ctx, hdrs, srcs, deps): public_hdrs = hdrs, compilation_contexts = compilation_contexts, ) - linking_info = cc_common.link( + (linking_context, linking_outputs) = cc_common.create_linking_context_from_compilation_outputs( actions = ctx.actions, name = "upb_lib", feature_configuration = feature_configuration, cc_toolchain = toolchain, - cc_compilation_outputs = compilation_info.cc_compilation_outputs, + compilation_outputs = compilation_outputs, linking_contexts = linking_contexts, ) return CcInfo( - compilation_context = compilation_info.compilation_context, - linking_context = linking_info.linking_context, + compilation_context = compilation_context, + linking_context = linking_context, ) def _compile_upb_protos(ctx, proto_info, proto_sources, ext): -- cgit v1.2.3 From 61034f50b336fea900b2fa02b4283d4ee078a3d6 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Tue, 7 May 2019 14:45:12 -0700 Subject: Fixed conflict error with Ragel on Bazel 0.25. --- BUILD | 4 ++-- ragel.BUILD | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/BUILD b/BUILD index 629287c..2f03ae3 100644 --- a/BUILD +++ b/BUILD @@ -543,8 +543,8 @@ genrule( name = "generate_json_ragel", srcs = ["upb/json/parser.rl"], outs = ["upb/json/parser.c"], - cmd = "$(location @ragel//:ragel) -C -o upb/json/parser.c $< && mv upb/json/parser.c $@", - tools = ["@ragel"], + cmd = "$(location @ragel//:ragelc) -C -o upb/json/parser.c $< && mv upb/json/parser.c $@", + tools = ["@ragel//:ragelc"], ) genrule( diff --git a/ragel.BUILD b/ragel.BUILD index 5485fab..5e3b249 100644 --- a/ragel.BUILD +++ b/ragel.BUILD @@ -4,7 +4,7 @@ package( ) cc_binary( - name = "ragel", + name = "ragelc", srcs = [ "ragel/rubycodegen.cpp", "ragel/goipgoto.h", -- cgit v1.2.3 From e294a16c08591b7715d48e40e82b1523f0227dfa Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Mon, 13 May 2019 07:12:09 -0700 Subject: Added name to cc_library_func() to avoid conflicts. --- build_defs.bzl | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/build_defs.bzl b/build_defs.bzl index 3e69680..6f956bf 100644 --- a/build_defs.bzl +++ b/build_defs.bzl @@ -272,7 +272,7 @@ def filter_none(elems): # upb_proto_library() rule -def cc_library_func(ctx, hdrs, srcs, deps): +def cc_library_func(ctx, name, hdrs, srcs, deps): compilation_contexts = [] linking_contexts = [] for dep in deps: @@ -289,14 +289,14 @@ def cc_library_func(ctx, hdrs, srcs, deps): actions = ctx.actions, feature_configuration = feature_configuration, cc_toolchain = toolchain, - name = "upb_lib", + name = name, srcs = srcs, public_hdrs = hdrs, compilation_contexts = compilation_contexts, ) (linking_context, linking_outputs) = cc_common.create_linking_context_from_compilation_outputs( actions = ctx.actions, - name = "upb_lib", + name = name, feature_configuration = feature_configuration, cc_toolchain = toolchain, compilation_outputs = compilation_outputs, @@ -356,6 +356,7 @@ def _upb_proto_aspect_impl(target, ctx): files = _compile_upb_protos(ctx, proto_info, proto_info.direct_sources, ctx.attr._ext) cc_info = cc_library_func( ctx = ctx, + name = ctx.rule.attr.name, hdrs = files.hdrs, srcs = files.srcs, deps = ctx.rule.attr.deps + [ctx.attr._upb], -- cgit v1.2.3 From cbe051a09c19f868b7682477755011ec681ce6cb Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Mon, 13 May 2019 08:30:57 -0700 Subject: Re-enabled conformance tests. --- BUILD | 78 ++++++++++++++++++++++++------------------------ CMakeLists.txt | 1 + WORKSPACE | 7 +++-- tools/make_cmakelists.py | 4 +-- 4 files changed, 47 insertions(+), 43 deletions(-) diff --git a/BUILD b/BUILD index 2f03ae3..6ad365e 100644 --- a/BUILD +++ b/BUILD @@ -350,45 +350,45 @@ cc_test( copts = CPPOPTS, ) -#upb_proto_library( -# name = "conformance_proto_upb", -# deps = ["@com_google_protobuf//:conformance_proto"], -#) - -#upb_proto_library( -# name = "test_messages_proto3_proto_upb", -# deps = ["@com_google_protobuf//:test_messages_proto3_proto"], -#) - -#cc_binary( -# name = "conformance_upb", -# srcs = [ -# "tests/conformance_upb.c", -# ], -# copts = COPTS + ["-Ibazel-out/k8-fastbuild/bin"], -# deps = [ -# ":conformance_proto_upb", -# ":test_messages_proto3_proto_upb", -# ":upb", -# ], -#) -# -#make_shell_script( -# name = "gen_test_conformance_upb", -# out = "test_conformance_upb.sh", -# contents = "$(rlocation com_google_protobuf/conformance_test_runner) $(rlocation upb/conformance_upb)", -#) -# -#sh_test( -# name = "test_conformance_upb", -# srcs = ["test_conformance_upb.sh"], -# data = [ -# "tests/conformance_upb_failures.txt", -# ":conformance_upb", -# "@bazel_tools//tools/bash/runfiles", -# "@com_google_protobuf//:conformance_test_runner", -# ], -#) +upb_proto_library( + name = "conformance_proto_upb", + deps = ["@com_google_protobuf//:conformance_proto"], +) + +upb_proto_library( + name = "test_messages_proto3_proto_upb", + deps = ["@com_google_protobuf//:test_messages_proto3_proto"], +) + +cc_binary( + name = "conformance_upb", + srcs = [ + "tests/conformance_upb.c", + ], + copts = COPTS + ["-Ibazel-out/k8-fastbuild/bin"], + deps = [ + ":conformance_proto_upb", + ":test_messages_proto3_proto_upb", + ":upb", + ], +) + +make_shell_script( + name = "gen_test_conformance_upb", + out = "test_conformance_upb.sh", + contents = "$(rlocation com_google_protobuf/conformance_test_runner) $(rlocation upb/conformance_upb)", +) + +sh_test( + name = "test_conformance_upb", + srcs = ["test_conformance_upb.sh"], + data = [ + "tests/conformance_upb_failures.txt", + ":conformance_upb", + "@bazel_tools//tools/bash/runfiles", + "@com_google_protobuf//:conformance_test_runner", + ], +) # Amalgamation ################################################################# diff --git a/CMakeLists.txt b/CMakeLists.txt index 3e08cd7..e6bc5b4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -115,6 +115,7 @@ target_link_libraries(upb_pb table upb) add_library(upb_json + generated_for_cmake/upb/json/parser.c upb/json/printer.c upb/json/parser.h upb/json/printer.h) diff --git a/WORKSPACE b/WORKSPACE index 254d113..4239c71 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -17,8 +17,11 @@ http_archive( git_repository( name = "com_google_protobuf", - commit = "ec1a70913e5793a7d0a7b5fbf7e0e4f75409dd41", - remote = "https://github.com/protocolbuffers/protobuf.git", + # TODO(haberman): update to protobuf branch oncd this is merged: + # https://github.com/protocolbuffers/protobuf/pull/6126 + #remote = "https://github.com/protocolbuffers/protobuf.git", + commit = "2996da4d817dd006cd8599c74ad2364a897d6107", + remote = "https://github.com/haberman/protobuf.git", ) http_archive( diff --git a/tools/make_cmakelists.py b/tools/make_cmakelists.py index e320be4..36d5375 100755 --- a/tools/make_cmakelists.py +++ b/tools/make_cmakelists.py @@ -43,8 +43,8 @@ class BuildFileFunctions(object): for file in files: if os.path.isfile(file): found_files.append(file) - elif os.path.isfile("generated/" + file): - found_files.append("generated/" + file) + elif os.path.isfile("generated_for_cmake/" + file): + found_files.append("generated_for_cmake/" + file) else: print("Warning: no such file: " + file) -- cgit v1.2.3 From 0fea70b4d9e6c0fd95420893607f462c7308e490 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Mon, 13 May 2019 10:07:06 -0700 Subject: Works with Bazel 0.24.1 and Bazel 0.25.2! --- WORKSPACE | 5 +++++ build_defs.bzl | 43 +++++++++++++++++++++++++++++++++++-------- repository_defs.bzl | 16 ++++++++++++++++ tools/make_cmakelists.py | 3 +++ 4 files changed, 59 insertions(+), 8 deletions(-) create mode 100644 repository_defs.bzl diff --git a/WORKSPACE b/WORKSPACE index 4239c71..780b3c4 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -3,6 +3,11 @@ workspace(name = "upb") load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository") +load(":repository_defs.bzl", "bazel_version_repository") + +bazel_version_repository( + name = "bazel_version" +) http_archive( name = "lua", diff --git a/build_defs.bzl b/build_defs.bzl index 6f956bf..38df359 100644 --- a/build_defs.bzl +++ b/build_defs.bzl @@ -1,6 +1,8 @@ load("@bazel_skylib//lib:paths.bzl", "paths") +load("@bazel_skylib//lib:versions.bzl", "versions") load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain") +load("@bazel_version//:bazel_version.bzl", "bazel_version") _shell_find_runfiles = """ # --- begin runfiles.bash initialization --- @@ -272,19 +274,42 @@ def filter_none(elems): # upb_proto_library() rule -def cc_library_func(ctx, name, hdrs, srcs, deps): - compilation_contexts = [] - linking_contexts = [] - for dep in deps: - if CcInfo in dep: - linking_contexts.append(dep[CcInfo].linking_context) - compilation_contexts.append(dep[CcInfo].compilation_context) +def cc_library_func(ctx, name, hdrs, srcs, dep_ccinfos): + compilation_contexts = [info.compilation_context for info in dep_ccinfos] + linking_contexts = [info.linking_context for info in dep_ccinfos] toolchain = find_cpp_toolchain(ctx) feature_configuration = cc_common.configure_features( cc_toolchain = toolchain, requested_features = ctx.features, unsupported_features = ctx.disabled_features, ) + + if is_bazel: + if bazel_version == "0.24.1": + # Compatibility code until gRPC is on 0.25.2 or later. + compilation_info = cc_common.compile( + ctx = ctx, + feature_configuration = feature_configuration, + cc_toolchain = toolchain, + srcs = srcs, + hdrs = hdrs, + compilation_contexts = compilation_contexts, + ) + linking_info = cc_common.link( + ctx = ctx, + feature_configuration = feature_configuration, + cc_toolchain = toolchain, + cc_compilation_outputs = compilation_info.cc_compilation_outputs, + linking_contexts = linking_contexts, + ) + return CcInfo( + compilation_context = compilation_info.compilation_context, + linking_context = linking_info.linking_context, + ) + + if not versions.is_at_least("0.25.2", bazel_version): + fail("upb requires Bazel >=0.25.2 or 0.24.1") + (compilation_context, compilation_outputs) = cc_common.compile( actions = ctx.actions, feature_configuration = feature_configuration, @@ -354,12 +379,14 @@ def _upb_proto_rule_impl(ctx): def _upb_proto_aspect_impl(target, ctx): proto_info = target[ProtoInfo] files = _compile_upb_protos(ctx, proto_info, proto_info.direct_sources, ctx.attr._ext) + deps = ctx.rule.attr.deps + [ctx.attr._upb] + dep_ccinfos = [dep[CcInfo] for dep in deps if CcInfo in dep] cc_info = cc_library_func( ctx = ctx, name = ctx.rule.attr.name, hdrs = files.hdrs, srcs = files.srcs, - deps = ctx.rule.attr.deps + [ctx.attr._upb], + dep_ccinfos = dep_ccinfos, ) return [cc_info] diff --git a/repository_defs.bzl b/repository_defs.bzl new file mode 100644 index 0000000..5bbc9cb --- /dev/null +++ b/repository_defs.bzl @@ -0,0 +1,16 @@ + +# A hacky way to work around the fact that native.bazel_version is only +# available from WORKSPACE macros, not BUILD macros or rules. +# +# Hopefully we can remove this if/when this is fixed: +# https://github.com/bazelbuild/bazel/issues/8305 + +def _impl(repository_ctx): + s = "bazel_version = \"" + native.bazel_version + "\"" + repository_ctx.file("bazel_version.bzl", s) + repository_ctx.file("BUILD", "") + +bazel_version_repository = repository_rule( + implementation=_impl, + local=True, +) diff --git a/tools/make_cmakelists.py b/tools/make_cmakelists.py index 36d5375..44cd1b0 100755 --- a/tools/make_cmakelists.py +++ b/tools/make_cmakelists.py @@ -175,6 +175,9 @@ class WorkspaceFileFunctions(object): def git_repository(self, **kwargs): pass + def bazel_version_repository(self, **kwargs): + pass + class Converter(object): def __init__(self): -- cgit v1.2.3 From f0605283962ca61f35587d542c4cd684548168bd Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Mon, 13 May 2019 10:12:51 -0700 Subject: Updated protobuf to point to main repo. --- WORKSPACE | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/WORKSPACE b/WORKSPACE index 780b3c4..bcb00f0 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -22,11 +22,8 @@ http_archive( git_repository( name = "com_google_protobuf", - # TODO(haberman): update to protobuf branch oncd this is merged: - # https://github.com/protocolbuffers/protobuf/pull/6126 - #remote = "https://github.com/protocolbuffers/protobuf.git", - commit = "2996da4d817dd006cd8599c74ad2364a897d6107", - remote = "https://github.com/haberman/protobuf.git", + remote = "https://github.com/protocolbuffers/protobuf.git", + commit = "78ca77ac8799f67fda7b9a01cc691cd9fe526f25", ) http_archive( -- cgit v1.2.3