diff --git a/.bazelrc b/.bazelrc index d8253dd2..31b24f32 100644 --- a/.bazelrc +++ b/.bazelrc @@ -1,3 +1,4 @@ +common --enable_bzlmod build -c opt # Make sure we still detect assertion failures build --copt=-UNDEBUG diff --git a/.gitignore b/.gitignore index 0d89a7ab..5e871f36 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ bazel-* compile_commands.json dist/ +MODULE.bazel.lock rust-project.json target/ tmp/ diff --git a/MODULE.bazel b/MODULE.bazel new file mode 100644 index 00000000..c1eee398 --- /dev/null +++ b/MODULE.bazel @@ -0,0 +1,97 @@ +# Copyright 2024 RISC Zero, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""The Zirgen Compiler""" + +module( + name = "zirgen", + repo_name = "risc0_zirgen", +) + +bazel_dep(name = "rules_license", version = "0.0.7") +bazel_dep(name = "rules_pkg", version = "1.0.1") +bazel_dep(name = "bazel_skylib", version = "1.7.1") +bazel_dep(name = "platforms", version = "0.0.10") + +bazel_dep(name = "googletest", version = "1.15.2", dev_dependency = True) + +# Generate compile_commands.json file for IDE integration +# https://github.com/hedronvision/bazel-compile-commands-extractor +# tip: use `bazel run @hedron_compile_commands//:refresh_all` +bazel_dep(name = "hedron_compile_commands", dev_dependency = True) +git_override( + module_name = "hedron_compile_commands", + remote = "https://github.com/hedronvision/bazel-compile-commands-extractor.git", + commit = "4f28899228fb3ad0126897876f147ca15026151e", +) + +http_archive = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + +# LLVM doesn't support bzlmod yet, so we have to pull it in the WORKSPACE way +LLVM_COMMIT = "fea7b65f23632b42ff8f7e2595ac0641e2c1d214" +LLVM_SHA256 = "7f8da8de897f20824e7d11204768ccb29a47419385bb6c9b3f5eccfd738d7510" +http_archive( + name = "llvm-raw", + build_file_content = "# empty", + sha256 = LLVM_SHA256, + strip_prefix = "llvm-project-" + LLVM_COMMIT, + urls = ["https://github.com/llvm/llvm-project/archive/{commit}.tar.gz".format(commit = LLVM_COMMIT)], +) + +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 = "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", + ], +) + +http_archive( + name = "riscv_tests", + build_file = "//bazel/third_party:riscv_tests.BUILD", + sha256 = "831a91955287865f9c09bbb7102f7ba2987d86823fd7b67c8a62eff46e21a83c", + strip_prefix = "riscv-tests-a6ab6ae6008ffc2ea907ea9f6d2b8379583e7d56", + url = "https://github.com/riscv/riscv-tests/archive/a6ab6ae6008ffc2ea907ea9f6d2b8379583e7d56.zip", +) + +http_archive( + name = "rules_conda", + patch_args = ["-p1"], + patches = ["//bazel/third_party/rules_conda:prefix.patch"], + sha256 = "9793f86162ec5cfb32a1f1f13f5bf776e2c06b243c4f1ee314b9ec870144220d", + url = "https://github.com/spietras/rules_conda/releases/download/0.1.0/rules_conda-0.1.0.zip", +) + +HERMETIC_CC_TOOLCHAIN_VERSION = "v3.1.0" + +http_archive( + name = "hermetic_cc_toolchain", + sha256 = "df091afc25d73b0948ed371d3d61beef29447f690508e02bc24e7001ccc12d38", + urls = [ + "https://mirror.bazel.build/github.com/uber/hermetic_cc_toolchain/releases/download/{0}/hermetic_cc_toolchain-{0}.tar.gz".format(HERMETIC_CC_TOOLCHAIN_VERSION), + "https://github.com/uber/hermetic_cc_toolchain/releases/download/{0}/hermetic_cc_toolchain-{0}.tar.gz".format(HERMETIC_CC_TOOLCHAIN_VERSION), + ], +) diff --git a/WORKSPACE b/WORKSPACE index 2f3c4e4b..e69de29b 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -1,120 +0,0 @@ -workspace(name = "zirgen") - -load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") - -load("//bazel/rules/zirgen:deps.bzl", "zirgen_dependencies") -zirgen_dependencies() - -load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace") -bazel_skylib_workspace() - -load("@llvm-raw//utils/bazel:configure.bzl", "llvm_configure") -llvm_configure(name = "llvm-project") - -load("//bazel/toolchain/risc0:repo.bzl", "risc0_toolchain") - -risc0_toolchain(name = "risc0_toolchain") - -load("//bazel/toolchain/rv32im-linux:repo.bzl", "rv32im_linux_toolchain") - -rv32im_linux_toolchain(name = "rv32im_linux_toolchain") - -http_archive( - name = "riscv_tests", - build_file = "//bazel/third_party:riscv_tests.BUILD", - sha256 = "831a91955287865f9c09bbb7102f7ba2987d86823fd7b67c8a62eff46e21a83c", - strip_prefix = "riscv-tests-a6ab6ae6008ffc2ea907ea9f6d2b8379583e7d56", - url = "https://github.com/riscv/riscv-tests/archive/a6ab6ae6008ffc2ea907ea9f6d2b8379583e7d56.zip", -) - -http_archive( - name = "rules_conda", - patch_args = ["-p1"], - patches = ["//bazel/third_party/rules_conda:prefix.patch"], - sha256 = "9793f86162ec5cfb32a1f1f13f5bf776e2c06b243c4f1ee314b9ec870144220d", - url = "https://github.com/spietras/rules_conda/releases/download/0.1.0/rules_conda-0.1.0.zip", -) - -load("@rules_conda//:defs.bzl", "conda_create", "load_conda", "register_toolchain") - -load_conda( - install_mamba = True, - installer = "miniforge", - quiet = False, -) - -conda_create( - name = "py3_env", - environment = "@//:environment.yml", - quiet = False, - use_mamba = True, -) - -register_toolchain(py3_env = "py3_env") - -register_toolchains( - "//bazel/rules/clang_format:toolchain", -) - -http_archive( - name = "com_google_googletest", - sha256 = "ad7fdba11ea011c1d925b3289cf4af2c66a352e18d4c7264392fead75e919363", - strip_prefix = "googletest-1.13.0", - url = "https://github.com/google/googletest/archive/refs/tags/v1.13.0.tar.gz", -) - -http_archive( - name = "rules_pkg", - sha256 = "8f9ee2dc10c1ae514ee599a8b42ed99fa262b757058f65ad3c384289ff70c4b8", - urls = [ - "https://mirror.bazel.build/github.com/bazelbuild/rules_pkg/releases/download/0.9.1/rules_pkg-0.9.1.tar.gz", - "https://github.com/bazelbuild/rules_pkg/releases/download/0.9.1/rules_pkg-0.9.1.tar.gz", - ], -) - -load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies") - -rules_pkg_dependencies() - -# Hedron's Compile Commands Extractor for Bazel -# https://github.com/hedronvision/bazel-compile-commands-extractor -# tip: use `bazel run @hedron_compile_commands//:refresh_all` -http_archive( - name = "hedron_compile_commands", - strip_prefix = "bazel-compile-commands-extractor-4f28899228fb3ad0126897876f147ca15026151e", - url = "https://github.com/hedronvision/bazel-compile-commands-extractor/archive/4f28899228fb3ad0126897876f147ca15026151e.tar.gz", -) - -load("@hedron_compile_commands//:workspace_setup.bzl", "hedron_compile_commands_setup") - -hedron_compile_commands_setup() - -load("@hedron_compile_commands//:workspace_setup_transitive.bzl", "hedron_compile_commands_setup_transitive") - -hedron_compile_commands_setup_transitive() - -load("@hedron_compile_commands//:workspace_setup_transitive_transitive.bzl", "hedron_compile_commands_setup_transitive_transitive") - -hedron_compile_commands_setup_transitive_transitive() - -load("@hedron_compile_commands//:workspace_setup_transitive_transitive_transitive.bzl", "hedron_compile_commands_setup_transitive_transitive_transitive") - -hedron_compile_commands_setup_transitive_transitive_transitive() - -HERMETIC_CC_TOOLCHAIN_VERSION = "v3.1.0" - -http_archive( - name = "hermetic_cc_toolchain", - sha256 = "df091afc25d73b0948ed371d3d61beef29447f690508e02bc24e7001ccc12d38", - urls = [ - "https://mirror.bazel.build/github.com/uber/hermetic_cc_toolchain/releases/download/{0}/hermetic_cc_toolchain-{0}.tar.gz".format(HERMETIC_CC_TOOLCHAIN_VERSION), - "https://github.com/uber/hermetic_cc_toolchain/releases/download/{0}/hermetic_cc_toolchain-{0}.tar.gz".format(HERMETIC_CC_TOOLCHAIN_VERSION), - ], -) - -load("@hermetic_cc_toolchain//toolchain:defs.bzl", zig_toolchains = "toolchains") - -# Plain zig_toolchains() will pick reasonable defaults. See -# toolchain/defs.bzl:toolchains on how to change the Zig SDK version and -# download URL. -zig_toolchains() diff --git a/WORKSPACE.bzlmod b/WORKSPACE.bzlmod new file mode 100644 index 00000000..c6de79c3 --- /dev/null +++ b/WORKSPACE.bzlmod @@ -0,0 +1,44 @@ +workspace(name = "zirgen") + +load("@llvm-raw//utils/bazel:configure.bzl", "llvm_configure") +llvm_configure(name = "llvm-project") + +load("//bazel/toolchain/risc0:repo.bzl", "risc0_toolchain") + +risc0_toolchain(name = "risc0_toolchain") + +load("//bazel/toolchain/rv32im-linux:repo.bzl", "rv32im_linux_toolchain") + +rv32im_linux_toolchain(name = "rv32im_linux_toolchain") + +load("@rules_conda//:defs.bzl", "conda_create", "load_conda", "register_toolchain") + +load_conda( + install_mamba = True, + installer = "miniforge", + quiet = False, +) + +conda_create( + name = "py3_env", + environment = "@//:environment.yml", + quiet = False, + use_mamba = True, +) + +register_toolchain(py3_env = "py3_env") + +register_toolchains( + "//bazel/rules/clang_format:toolchain", +) + +load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies") + +rules_pkg_dependencies() + +load("@hermetic_cc_toolchain//toolchain:defs.bzl", zig_toolchains = "toolchains") + +# Plain zig_toolchains() will pick reasonable defaults. See +# toolchain/defs.bzl:toolchains on how to change the Zig SDK version and +# download URL. +zig_toolchains() diff --git a/bazel/rules/zirgen/deps.bzl b/bazel/rules/zirgen/deps.bzl deleted file mode 100644 index fa22f402..00000000 --- a/bazel/rules/zirgen/deps.bzl +++ /dev/null @@ -1,63 +0,0 @@ -""" -Utility to resolve Zirgen compiler dependencies -""" - -load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") -load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") - -def zirgen_dependencies(): - """ - Resolve Zirgen compiler dependencies. - - usage: - ``` - load("//bazel/rules/zirgen:deps.bzl", "zirgen_dependencies") - zirgen_dependencies() - - load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace") - bazel_skylib_workspace() - - load("@llvm-raw//utils/bazel:configure.bzl", "llvm_configure") - llvm_configure(name = "llvm-project") - ``` - """ - http_archive( - name = "bazel_skylib", - sha256 = "bc283cdfcd526a52c3201279cda4bc298652efa898b10b4db0837dc51652756f", - urls = [ - "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.7.1/bazel-skylib-1.7.1.tar.gz", - "https://github.com/bazelbuild/bazel-skylib/releases/download/1.7.1/bazel-skylib-1.7.1.tar.gz", - ], - ) - - LLVM_COMMIT = "fea7b65f23632b42ff8f7e2595ac0641e2c1d214" - LLVM_SHA256 = "7f8da8de897f20824e7d11204768ccb29a47419385bb6c9b3f5eccfd738d7510" - http_archive( - name = "llvm-raw", - build_file_content = "# empty", - sha256 = LLVM_SHA256, - strip_prefix = "llvm-project-" + LLVM_COMMIT, - urls = ["https://github.com/llvm/llvm-project/archive/{commit}.tar.gz".format(commit = LLVM_COMMIT)], - ) - - 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", - ], - ) - - 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", - ], - ) diff --git a/risc0/core/test/BUILD.bazel b/risc0/core/test/BUILD.bazel index 904cf208..e31669cb 100644 --- a/risc0/core/test/BUILD.bazel +++ b/risc0/core/test/BUILD.bazel @@ -5,6 +5,6 @@ cc_library( visibility = ["//visibility:public"], deps = [ "//risc0/core", - "@com_google_googletest//:gtest", + "@googletest//:gtest", ], ) diff --git a/zirgen/circuit/rv32im/shared/test/defs.bzl b/zirgen/circuit/rv32im/shared/test/defs.bzl index f92d76cc..522973c9 100644 --- a/zirgen/circuit/rv32im/shared/test/defs.bzl +++ b/zirgen/circuit/rv32im/shared/test/defs.bzl @@ -70,15 +70,15 @@ def compile_riscv_tests(): Label("@riscv_tests//:isa/macros/scalar/test_macros.h"), ], copts = [ - "-Iexternal/riscv_tests", - "-Iexternal/riscv_tests/isa/macros/scalar", + "-Iexternal/_main~_repo_rules~riscv_tests", + "-Iexternal/_main~_repo_rules~riscv_tests/isa/macros/scalar", "-Izirgen/circuit/rv32im/shared/test", "-Iexternal/zirgen/zirgen/circuit/rv32im/shared/test" ], ) all_bins = all_bins + [test] native.filegroup( - name = "riscv_test_bins", + name = "riscv_test_bins", srcs = all_bins, visibility = ["//visibility:public"], ) diff --git a/zirgen/components/test/BUILD.bazel b/zirgen/components/test/BUILD.bazel index c3255f32..8ed49138 100644 --- a/zirgen/components/test/BUILD.bazel +++ b/zirgen/components/test/BUILD.bazel @@ -31,6 +31,6 @@ cc_test( ], deps = [ ":test_utils", - "@com_google_googletest//:gtest_main", + "@googletest//:gtest_main", ], )