Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,9 @@
startup --windows_enable_symlinks

common --enable_bzlmod
# required for hybrid bzlmod+workspace builds
common --enable_workspace
common --incompatible_disallow_empty_glob

common --action_env=BAZEL_CXXOPTS=-std=c++17
common --cxxopt='-std=c++17'

try-import %workspace%/third_party/llvm-project/utils/bazel/.bazelrc

build --macos_sdk_version=15.0 --host_macos_minimum_os=11.0 --repo_env=CC=clang --repo_env=CXX=clang++ --cxxopt=--std=c++17 --cxxopt=-Wno-return-type --cxxopt=-Wno-trigraphs --cxxopt=-Wno-implicit-const-int-float-conversion --cxxopt=-Wno-c++11-narrowing --@llvm_zlib//:llvm_enable_zlib=false
2 changes: 1 addition & 1 deletion .bazelversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8.3.1
8.6.0
48 changes: 43 additions & 5 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
module(name = "jsir")

# https://registry.bazel.build/modules/bazel_skylib
bazel_dep(name = "bazel_skylib", version = "1.9.0")

# https://registry.bazel.build/modules/rules_license
# Required because gentbl_rule implicitly depends on //:license.
bazel_dep(name = "rules_license", version = "1.0.0")

# https://registry.bazel.build/modules/platforms
# Required by llvm-project's BUILD files.
bazel_dep(name = "platforms", version = "1.1.0")

# https://registry.bazel.build/modules/rules_cc
bazel_dep(name = "rules_cc", version = "0.1.4")
bazel_dep(name = "rules_cc", version = "0.2.0")

# https://registry.bazel.build/modules/rules_python
bazel_dep(name = "rules_python", version = "0.38.0")
bazel_dep(name = "rules_python", version = "1.0.0")

pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip")
pip.parse(
Expand All @@ -13,13 +26,13 @@ pip.parse(
use_repo(pip, "pypi")

# https://registry.bazel.build/modules/abseil-cpp
bazel_dep(name = "abseil-cpp", version = "20250814.1")
bazel_dep(name = "abseil-cpp", version = "20260526.0")

# https://registry.bazel.build/modules/nlohmann_json
bazel_dep(name = "nlohmann_json", version = "3.11.3")

# https://registry.bazel.build/modules/googletest
bazel_dep(name = "googletest", version = "1.15.0")
bazel_dep(name = "googletest", version = "1.17.0")

# https://registry.bazel.build/modules/protobuf
bazel_dep(
Expand All @@ -29,4 +42,29 @@ bazel_dep(
)

# https://registry.bazel.build/modules/re2
bazel_dep(name = "re2", version = "2024-07-02")
bazel_dep(name = "re2", version = "2024-07-02.bcr.1")

# LLVM and QuickJS are not in BCR; fetch them via a module extension.
llvm_extensions = use_extension("//bazel:extensions.bzl", "llvm_deps")
use_repo(
llvm_extensions,
"llvm-raw",
"llvm_zlib",
"llvm_zstd",
"quickjs",
)

# The subset of LLVM backend targets to compile. NVPTX is required because
# mlir/test:TestGPU depends on //llvm:NVPTXCodeGen (see setup_llvm.bzl comment).
_LLVM_TARGETS = [
"AArch64",
"NVPTX",
"X86",
]

llvm_configure = use_repo_rule("@llvm-raw//utils/bazel:configure.bzl", "llvm_configure")

llvm_configure(
name = "llvm-project",
targets = _LLVM_TARGETS,
)
157 changes: 120 additions & 37 deletions MODULE.bazel.lock

Large diffs are not rendered by default.

77 changes: 2 additions & 75 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,75 +1,2 @@
workspace(name = "com_google_maldoca")

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")

# provides the `license` rule, which is required because gentbl_rule implicitly
# depends upon the target '//:license'. How bizarre.
http_archive(
name = "rules_license",
sha256 = "6157e1e68378532d0241ecd15d3c45f6e5cfd98fc10846045509fb2a7cc9e381",
urls = [
"https://github.com/bazelbuild/rules_license/releases/download/0.0.4/rules_license-0.0.4.tar.gz",
],
)

http_archive(
name = "bazel_skylib",
sha256 = "74d544d96f4a5bb630d465ca8bbcfe231e3594e5aae57e1edbf17a6eb3ca2506",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.3.0/bazel-skylib-1.3.0.tar.gz",
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.3.0/bazel-skylib-1.3.0.tar.gz",
],
)

load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")

bazel_skylib_workspace()

# LLVM is pinned to the same commit used in the Google monorepo, and then
# imported into this workspace as a git repository. Then the build files
# defined in the LLVM monorepo are overlaid using llvm_configure in the setup
# script below. This defines the @llvm-project which is used for llvm build
# dependencies.
load("//bazel:import_llvm.bzl", "import_llvm")

import_llvm("llvm-raw")

load("//bazel:setup_llvm.bzl", "setup_llvm")

setup_llvm("llvm-project")

# LLVM doesn't have proper support for excluding the optional llvm_zstd and
# llvm_zlib dependencies but it is supposed to make LLVM faster, so why not
# include it.
# See https://reviews.llvm.org/D143344#4232172
maybe(
http_archive,
name = "llvm_zstd",
build_file = "@llvm-raw//utils/bazel/third_party_build:zstd.BUILD",
sha256 = "7c42d56fac126929a6a85dbc73ff1db2411d04f104fae9bdea51305663a83fd0",
strip_prefix = "zstd-1.5.2",
urls = [
"https://github.com/facebook/zstd/releases/download/v1.5.2/zstd-1.5.2.tar.gz",
],
)

maybe(
http_archive,
name = "llvm_zlib",
build_file = "@llvm-raw//utils/bazel/third_party_build:zlib-ng.BUILD",
sha256 = "e36bb346c00472a1f9ff2a0a4643e590a254be6379da7cddd9daeb9a7f296731",
strip_prefix = "zlib-ng-2.0.7",
urls = [
"https://github.com/zlib-ng/zlib-ng/archive/refs/tags/2.0.7.zip",
],
)

http_archive(
name = "quickjs",
build_file = "@//:bazel/quickjs.BUILD",
sha256 = "3c4bf8f895bfa54beb486c8d1218112771ecfc5ac3be1036851ef41568212e03",
urls = ["https://bellard.org/quickjs/quickjs-2024-01-13.tar.xz"],
strip_prefix = "quickjs-2024-01-13",
add_prefix = "quickjs",
)
# This file is intentionally empty.
# All dependencies are managed via MODULE.bazel (Bazel bzlmod).
10 changes: 2 additions & 8 deletions bazel/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,8 @@ load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
package(default_applicable_licenses = ["//:license"])

bzl_library(
name = "import_llvm_bzl",
srcs = ["import_llvm.bzl"],
visibility = ["//visibility:private"],
)

bzl_library(
name = "setup_llvm_bzl",
srcs = ["setup_llvm.bzl"],
name = "extensions_bzl",
srcs = ["extensions.bzl"],
visibility = ["//visibility:private"],
)

Expand Down
56 changes: 56 additions & 0 deletions bazel/extensions.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
"""Module extensions for non-BCR dependencies."""

load("@bazel_tools//tools/build_defs/repo:git.bzl", "new_git_repository")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")

def _llvm_deps_impl(_):
"""Implementation of the llvm_deps module extension."""

# LLVM is pinned to the same tag used in the Google monorepo.
# The build files from the LLVM monorepo are overlaid via llvm_configure
# (called via use_repo_rule in MODULE.bazel) to produce @llvm-project.
new_git_repository(
name = "llvm-raw",
build_file_content = "# empty",
tag = "llvmorg-22-init",
init_submodules = False,
remote = "https://github.com/llvm/llvm-project.git",
)

# Optional LLVM dependencies for performance. The build has no way to omit
# them. See https://reviews.llvm.org/D143344#4232172
maybe(
http_archive,
name = "llvm_zstd",
build_file = "@llvm-raw//utils/bazel/third_party_build:zstd.BUILD",
sha256 = "7c42d56fac126929a6a85dbc73ff1db2411d04f104fae9bdea51305663a83fd0",
strip_prefix = "zstd-1.5.2",
urls = [
"https://github.com/facebook/zstd/releases/download/v1.5.2/zstd-1.5.2.tar.gz",
],
)

maybe(
http_archive,
name = "llvm_zlib",
build_file = "@llvm-raw//utils/bazel/third_party_build:zlib-ng.BUILD",
sha256 = "e36bb346c00472a1f9ff2a0a4643e590a254be6379da7cddd9daeb9a7f296731",
strip_prefix = "zlib-ng-2.0.7",
urls = [
"https://github.com/zlib-ng/zlib-ng/archive/refs/tags/2.0.7.zip",
],
)

http_archive(
name = "quickjs",
build_file = "@jsir//:bazel/quickjs.BUILD",
sha256 = "3c4bf8f895bfa54beb486c8d1218112771ecfc5ac3be1036851ef41568212e03",
urls = ["https://bellard.org/quickjs/quickjs-2024-01-13.tar.xz"],
strip_prefix = "quickjs-2024-01-13",
add_prefix = "quickjs",
)

llvm_deps = module_extension(
implementation = _llvm_deps_impl,
)
19 changes: 0 additions & 19 deletions bazel/import_llvm.bzl

This file was deleted.

24 changes: 0 additions & 24 deletions bazel/setup_llvm.bzl

This file was deleted.

3 changes: 2 additions & 1 deletion maldoca/base/get_runfiles_dir.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ std::string GetDataDependencyFilepath(absl::string_view path) {
std::unique_ptr<Runfiles> runfiles(
Runfiles::CreateForTest(BAZEL_CURRENT_REPOSITORY, &error));
CHECK(runfiles != nullptr) << error;
return runfiles->Rlocation(JoinPath("com_google_maldoca", path));
// In bzlmod, the root module's canonical repo name is always "_main".
return runfiles->Rlocation(JoinPath("_main", path));
}

std::string GetRunfilesDir() { return GetDataDependencyFilepath(""); }
Expand Down
15 changes: 14 additions & 1 deletion maldoca/js/ir/lit.cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,20 @@
config.test_format = lit.formats.ShTest(execute_external=True)

runfiles_dir = pathlib.Path(os.environ["RUNFILES_DIR"])
llvm_dir = runfiles_dir.joinpath("llvm-project/llvm")

# In bzlmod, external repos use canonical names (e.g. "+_repo_rules+llvm-project")
# rather than apparent names. Parse _repo_mapping to resolve "llvm-project" from
# the root module's perspective so this works in both WORKSPACE and bzlmod mode.
def _canonical_repo(apparent_name):
repo_mapping = runfiles_dir / "_repo_mapping"
if repo_mapping.exists():
for line in repo_mapping.read_text().splitlines():
parts = line.split(",")
if len(parts) == 3 and parts[0] == "" and parts[1] == apparent_name:
return parts[2]
return apparent_name

llvm_dir = runfiles_dir.joinpath(_canonical_repo("llvm-project"), "llvm")
jsir_dir = runfiles_dir.joinpath("_main/maldoca/js/ir")

config.environment["PATH"] = (
Expand Down
Loading