diff --git a/utils/bazel/WORKSPACE b/utils/bazel/WORKSPACE --- a/utils/bazel/WORKSPACE +++ b/utils/bazel/WORKSPACE @@ -2,10 +2,20 @@ # See https://llvm.org/LICENSE.txt for license information. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -load(":configure.bzl", "llvm_configure") load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") +http_archive( + name = "bazel_skylib", + sha256 = "97e70364e9249702246c0e9444bccdc4b847bed1eb03c5a3ece4f83dfe6abc44", + urls = [ + "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.0.2/bazel-skylib-1.0.2.tar.gz", + "https://github.com/bazelbuild/bazel-skylib/releases/download/1.0.2/bazel-skylib-1.0.2.tar.gz", + ], +) + +load(":configure.bzl", "llvm_configure") + llvm_configure( name = "llvm-project", overlay_path = "llvm-project-overlay", @@ -57,19 +67,6 @@ name = "vulkan_sdk", ) -http_archive( - name = "bazel_skylib", - sha256 = "97e70364e9249702246c0e9444bccdc4b847bed1eb03c5a3ece4f83dfe6abc44", - urls = [ - "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.0.2/bazel-skylib-1.0.2.tar.gz", - "https://github.com/bazelbuild/bazel-skylib/releases/download/1.0.2/bazel-skylib-1.0.2.tar.gz", - ], -) - -load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace") - -bazel_skylib_workspace() - http_archive( name = "bazel_toolchains", sha256 = "1adf5db506a7e3c465a26988514cfc3971af6d5b3c2218925cd6e71ee443fc3f", diff --git a/utils/bazel/configure.bzl b/utils/bazel/configure.bzl --- a/utils/bazel/configure.bzl +++ b/utils/bazel/configure.bzl @@ -5,6 +5,7 @@ """Helper macros to configure the LLVM overlay project.""" load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") +load("@bazel_skylib//lib:paths.bzl", "paths") load(":zlib.bzl", "llvm_zlib_disable", "llvm_zlib_system") load(":terminfo.bzl", "llvm_terminfo_disable", "llvm_terminfo_system") @@ -26,32 +27,17 @@ "X86", ] -def _is_absolute(path): - """Returns `True` if `path` is an absolute path. - - Args: - path: A path (which is a string). - Returns: - `True` if `path` is an absolute path. - """ - return path.startswith("/") or (len(path) > 2 and path[1] == ":") - -def _join_path(a, b): - if _is_absolute(b): - return b - return str(a) + "/" + str(b) - def _overlay_directories(repository_ctx): - src_workspace_path = repository_ctx.path( + src_workspace_path = str(repository_ctx.path( repository_ctx.attr.src_workspace, - ).dirname + ).dirname) - src_path = _join_path(src_workspace_path, repository_ctx.attr.src_path) + src_path = paths.join(src_workspace_path, repository_ctx.attr.src_path) - overlay_workspace_path = repository_ctx.path( + overlay_workspace_path = str(repository_ctx.path( repository_ctx.attr.overlay_workspace, - ).dirname - overlay_path = _join_path( + ).dirname) + overlay_path = paths.join( overlay_workspace_path, repository_ctx.attr.overlay_path, ) diff --git a/utils/bazel/examples/http_archive/WORKSPACE b/utils/bazel/examples/http_archive/WORKSPACE --- a/utils/bazel/examples/http_archive/WORKSPACE +++ b/utils/bazel/examples/http_archive/WORKSPACE @@ -8,6 +8,15 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") +http_archive( + name = "bazel_skylib", + sha256 = "97e70364e9249702246c0e9444bccdc4b847bed1eb03c5a3ece4f83dfe6abc44", + urls = [ + "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.0.2/bazel-skylib-1.0.2.tar.gz", + "https://github.com/bazelbuild/bazel-skylib/releases/download/1.0.2/bazel-skylib-1.0.2.tar.gz", + ], +) + # Replace with the LLVM commit you want to use. LLVM_COMMIT = "09ac97ce350316b95b8cddb796d52f71b6f68296" diff --git a/utils/bazel/examples/submodule/WORKSPACE b/utils/bazel/examples/submodule/WORKSPACE --- a/utils/bazel/examples/submodule/WORKSPACE +++ b/utils/bazel/examples/submodule/WORKSPACE @@ -6,6 +6,15 @@ workspace(name = "submodule_example") +http_archive( + name = "bazel_skylib", + sha256 = "97e70364e9249702246c0e9444bccdc4b847bed1eb03c5a3ece4f83dfe6abc44", + urls = [ + "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.0.2/bazel-skylib-1.0.2.tar.gz", + "https://github.com/bazelbuild/bazel-skylib/releases/download/1.0.2/bazel-skylib-1.0.2.tar.gz", + ], +) + # Or wherever your submodule is located. SUBMODULE_PATH = "third_party/llvm-project" diff --git a/utils/bazel/llvm-project-overlay/mlir/tblgen.bzl b/utils/bazel/llvm-project-overlay/mlir/tblgen.bzl --- a/utils/bazel/llvm-project-overlay/mlir/tblgen.bzl +++ b/utils/bazel/llvm-project-overlay/mlir/tblgen.bzl @@ -3,6 +3,9 @@ # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception """BUILD extensions for MLIR table generation.""" +load("@bazel_skylib//lib:paths.bzl", "paths") + + TdInfo = provider( "Holds TableGen files and the dependencies and include paths necessary to" + " build them.", @@ -69,8 +72,8 @@ prefixed_includes = [] for include in includes: prefixed_includes.append(include) - prefixed_includes.append(ctx.genfiles_dir.path + "/" + include) - prefixed_includes.append(ctx.bin_dir.path + "/" + include) + prefixed_includes.append(paths.join(ctx.genfiles_dir.path, include)) + prefixed_includes.append(paths.join(ctx.bin_dir.path, include)) return prefixed_includes def _resolve_includes(ctx, includes): @@ -84,9 +87,11 @@ workspace_root = workspace_root if workspace_root else "." resolved_includes = [] for include in includes: - if not include.startswith("/"): - include = "/" + package + "/" + include - include = workspace_root + include + if paths.is_absolute(include): + include = include.lstrip("/") + else: + include = paths.join(package, include) + include = paths.join(workspace_root, include) resolved_includes.extend(_prefix_roots(ctx, [include])) return resolved_includes @@ -329,12 +334,15 @@ **kwargs: Extra keyword arguments to pass to all generated rules. """ - llvm_project_execroot_path = Label("//mlir:tblgen.bzl", relative_to_caller_repository = False).workspace_root + llvm_project_execroot_path = Label( + "//mlir:tblgen.bzl", + relative_to_caller_repository = False, + ).workspace_root # TODO(gcmn): Update callers to td_library and explicit includes and drop # this hardcoded include. hardcoded_includes = [ - "%s/mlir/include" % llvm_project_execroot_path, + paths.join(llvm_project_execroot_path, "mlir/include"), ] for (opts, out) in tbl_outs: diff --git a/utils/bazel/llvm_configs/BUILD.bazel b/utils/bazel/llvm_configs/BUILD.bazel --- a/utils/bazel/llvm_configs/BUILD.bazel +++ b/utils/bazel/llvm_configs/BUILD.bazel @@ -2,11 +2,12 @@ # See https://llvm.org/LICENSE.txt for license information. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -# We perform diff testing here to avoid any in-tree BUILD files depending on -# bazel_sklyib. These diff tests ensure that the current Bazel configuration -# does not drift from the configuration in the .cmake files, since we don't -# alway use them directly (and even if we did we wouldn't necessarily pick up -# changes there). These are literal change-detector tests. +# These diff tests ensure that the current Bazel configurationdoes not drift +# from the configuration in the .cmake files, since we don't alway use them +# directly (and even if we did we wouldn't necessarily pick up changes there). +# These are literal change-detector tests. We perform diff testing here since +# it isn't really part of building LLVM and we don't want to include the config +# copies in the workspace used by dependent projects. load("@bazel_skylib//rules:diff_test.bzl", "diff_test")