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: 2 additions & 2 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
test --test_output=all
test --verbose_failures

build --java_runtime_version=remotejdk_17
build --tool_java_runtime_version=remotejdk_17
build --java_runtime_version=local_jdk
build --tool_java_runtime_version=local_jdk
4 changes: 4 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ jobs:
- run:
name: example tests
command: cd examples/simple && bazel test //...
- run:
name: stress tests
command: cd examples/stress && bazel test //...


workflows:
test-workflow:
Expand Down
27 changes: 22 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Note that `clojure_library` AOT is _non-transitive_. By default `(clojure.core/c

If you don't need to AOT, `clojure_library` isn't necessary, just use `java_library` with `resource_strip_prefix`.

Note that AOT will determine whether a library should appear in `deps` or `runtime_deps`. If a library is being AOT'd, everything that it requires will need to appear in `deps`. If it is not being AOT'd, dependencies should be listed in `runtime_deps`.
Note that AOT will determine whether a library should appear in `deps` or `runtime_deps`. If a library is being AOT'd, everything that it loads at compile time will need to appear in `deps`. If it is not being AOT'd, dependencies should be listed in `runtime_deps`.

### clojure_repl

Expand Down Expand Up @@ -177,19 +177,21 @@ Prefer namespace metadata for specifying extra dependencies in your code. Howeve

put `:bazel {:deps {}}` at the top level of your deps.edn file. `:deps` will be merged in when running `gen_srcs`. Deps are a map of bazel labels to a map of extra fields to merge into the `clojure_library`.

`examples/stress/deps.edn` contains known examples of libraries that require extra annotations to compile under rules clojure.

### no AOT

```clojure
:bazel {:no-aot #{foo.bar}}
```

Instructs gen-build to not AOT that namespace.
Instructs gen-build to not AOT that namespace. Note that this doesn't affect 3rd party dependencies yet.

### Coarse dependencies

Fine grained dependencies are ideal from an efficiency perspective, but it isn't always possible to make them work.

`gen_srcs` also creates a few extra targets in every directory on the deps.edn search path. It will produce `clojure_library` targets named `__clj_lib` containing all source files in the directory (non-AOT'd), and all subpackages. `//src:__clj_files` includes all src files under `src`. These targets are useful for static analysis tools.
`gen_srcs` also creates a few extra targets in every directory on the deps.edn search path. It will produce `clojure_library` targets named `__clj_lib` containing all source files in the directory (non-AOT'd), and all subpackages. `//src:__clj_files` includes all src files under `src`. These targets are useful for e.g. static analysis tools like clj-kondo.

`__clj_lib` does not include dependencies. Use `@deps//:__all` to pull in all dependencies.

Expand Down Expand Up @@ -294,13 +296,28 @@ This makes things much nicer and more standard for users of the rules.
- builds are non-reproducible for one reason:
- there isn't a public API to reset the ID clojure uses for naming anonymous functions, which means anonymous AOT function names are non-deterministic
- When using gen-deps, I haven't found a way to identify :provided dependencies. Those have to be added by hand for now
- Do not use `user.clj`. If there is a user.clj at the root of your classpath, it will be loaded every time a new Clojure runtime is created, which can be many times during an AOT job. Additionally, dependencies in the user.clj are invisible to `gen-build`

# Compatibility

rules_clojure requires JDK 17 or higher. It is currently tested with Bazel 7.4.1 and JDK21
rules_clojure requires JDK 21 or higher. It is currently tested with Bazel 7.4.1 and JDK21

# Thanks

- Forked from https://github.com/simuons/rules_clojure
- Additional inspiration from https://github.com/markdingram/bazel-clojure
- Contains vendored code from tools.namespace https://github.com/clojure/tools.namespace
- Contains vendored code from tools.reader https://github.com/clojure/tools.reader
- Contains vendored code from java.classpath https://github.com/clojure/java.classpath



Copyright and License
----------------------------------------

Copyright © 2025 Griffin Bank. All rights reserved. The use and
distribution terms for this software are covered by the
[Eclipse Public License 1.0] which can be found in the file
epl-v10.html at the root of this distribution. By using this software
in any fashion, you are agreeing to be bound by the terms of this
license. You must not remove this notice, or any other, from this
software.
15 changes: 9 additions & 6 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ maven_install(
maven.artifact(
group = "org.clojure",
artifact = "clojure",
version = "1.11.1",
version = "1.12.1",
exclusions = [
"org.clojure:spec.alpha",
"org.clojure:core.specs.alpha"
Expand All @@ -36,21 +36,19 @@ maven_install(
maven.artifact(
group = "org.clojure",
artifact = "spec.alpha",
version = "0.3.218",
version = "0.5.238",
exclusions = ["org.clojure:clojure"]
),
maven.artifact(
group = "org.clojure",
artifact = "core.specs.alpha",
version = "0.2.62",
version = "0.4.74",
exclusions = [
"org.clojure:clojure",
"org.clojure:spec.alpha"
]
),
"org.clojure:data.json:2.4.0",
"org.clojure:java.classpath:1.0.0",
"org.clojure:tools.namespace:1.1.0",
"org.clojure:tools.deps.alpha:0.14.1212"
],
maven_install_json = "@//:frozen_deps_install.json",
Expand All @@ -75,9 +73,14 @@ rules_clojure_setup()
maven_install(
name = "clojure_old",
artifacts = [
"org.clojure:clojure:1.8.0",],
"org.clojure:clojure:1.8.0"],
fail_if_repin_required = True,
repositories = [
"https://repo1.maven.org/maven2",
"https://repo.clojars.org/"
])

local_repository(
name = "example-simple",
path = "examples/simple",
)
3 changes: 1 addition & 2 deletions deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@
{:paths ["src", "classes"]
:deps {org.clojure/data.json {:mvn/version "2.4.0"}
org.clojure/java.classpath {:mvn/version "1.0.0"}
org.clojure/tools.deps.alpha {:mvn/version "0.14.1212"}
org.clojure/tools.namespace {:mvn/version "1.1.0"}}
org.clojure/tools.deps.alpha {:mvn/version "0.14.1212"}}
:aliases {:dev {:extra-paths "test"}}}
Binary file modified deps/rules_clojure_maven_deps.zip
Binary file not shown.
5 changes: 2 additions & 3 deletions examples/simple/.bazelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
build --java_runtime_version=remotejdk_17
build --tool_java_language_version=17
build --tool_java_runtime_version=remotejdk_17
build --java_runtime_version=local_jdk
build --tool_java_runtime_version=local_jdk
2 changes: 1 addition & 1 deletion examples/simple/deps.edn
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{:deps
{org.clojure/clojure {:mvn/version "1.11.1"}}
{org.clojure/clojure {:mvn/version "1.12.1"}}
:paths ["src"]}
4 changes: 4 additions & 0 deletions examples/simple/src/example/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ load("@rules_clojure//:rules.bzl", "clojure_library", "clojure_binary")

package(default_visibility = ["//visibility:public"])

java_library(name="src",
resources=glob(["*.clj"]),
resource_strip_prefix="src")

clojure_library(name="core",
srcs=["core.clj"],
resource_strip_prefix="src",
Expand Down
1 change: 1 addition & 0 deletions examples/stress/.bazeliskrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
USE_BAZEL_VERSION=7.4.1
5 changes: 5 additions & 0 deletions examples/stress/.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
test --test_output=all
test --verbose_failures

build --java_runtime_version=local_jdk
build --tool_java_runtime_version=local_jdk
8 changes: 8 additions & 0 deletions examples/stress/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
load("@rules_clojure//rules:tools_deps.bzl", "clojure_gen_namespace_loader", "clojure_gen_srcs")

clojure_gen_srcs(name = "gen_srcs")

package(default_visibility = ["//visibility:public"])

exports_files([
"deps.edn"])
24 changes: 24 additions & 0 deletions examples/stress/WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
workspace(name = "example-stress")

local_repository(
name = "rules_clojure",
path = "../../",
)

load("@rules_clojure//:repositories.bzl", "rules_clojure_deps")
rules_clojure_deps()

load("@rules_clojure//:setup.bzl", "rules_clojure_setup")
rules_clojure_setup()

load("@rules_clojure//rules:tools_deps.bzl", "clojure_tools_deps")

clojure_tools_deps(
name = "deps", # name of the bazel repo that will contain CLJ dependencies
aliases = [
# extra deps.edn aliases to include
"dev",
"test",
],
deps_edn = "//:deps.edn",
)
30 changes: 30 additions & 0 deletions examples/stress/deps.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{:deps
{org.clojure/clojure {:mvn/version "1.12.1"}
techascent/tech.ml.dataset {:mvn/version "7.055"}
fipp/fipp {:mvn/version "0.6.27"}
org.clojure/tools.deps.alpha {:mvn/version "0.14.1222"}}
:paths ["src" "test"]
:mvn/repos {"maven" {:url "https://repo1.maven.org/maven2"}
"clojars" {:url "https://repo.clojars.org/"}}
:bazel {:deps {"@deps//:ns_com_cnuernber_ham_fisted_ham_fisted_alists" {:deps ["@deps//:ns_com_cnuernber_ham_fisted_ham_fisted_print"]}

"@deps//:ns_cnuernber_dtype_next_tech_v3_datatype_api" {:deps ["@deps//:ns_cnuernber_dtype_next_tech_v3_datatype_argtypes"
"@deps//:ns_cnuernber_dtype_next_tech_v3_datatype_base"
"@deps//:ns_cnuernber_dtype_next_tech_v3_datatype_array_buffer"
"@deps//:ns_cnuernber_dtype_next_tech_v3_datatype_native_buffer"
"@deps//:ns_cnuernber_dtype_next_tech_v3_datatype_emap"
"@deps//:ns_cnuernber_dtype_next_tech_v3_datatype_io_indexed_buffer"
"@deps//:ns_cnuernber_dtype_next_tech_v3_datatype_const_reader"
"@deps//:ns_cnuernber_dtype_next_tech_v3_datatype_io_concat_buffer"
"@deps//:ns_cnuernber_dtype_next_tech_v3_datatype_copy_make_container"]}

"@deps//:ns_cnuernber_dtype_next_tech_v3_datatype_datetime_api" {:deps ["@deps//:ns_cnuernber_dtype_next_tech_v3_datatype_datetime_constants"
"@deps//:ns_cnuernber_dtype_next_tech_v3_datatype_datetime_base"
"@deps//:ns_cnuernber_dtype_next_tech_v3_datatype_datetime_operations"]}
"@deps//:ns_cnuernber_dtype_next_tech_v3_datatype_functional_api" {:deps ["@deps//:ns_cnuernber_dtype_next_tech_v3_datatype_statistics"]}
"@deps//:ns_techascent_tech_ml_dataset_tech_v3_dataset_api" {:deps ["@deps//:ns_techascent_tech_ml_dataset_tech_v3_dataset_base"
"@deps//:ns_techascent_tech_ml_dataset_tech_v3_dataset_readers"
"@deps//:ns_techascent_tech_ml_dataset_tech_v3_dataset_impl_dataset"
"@deps//:ns_techascent_tech_ml_dataset_tech_v3_dataset_column"
"@deps//:ns_techascent_tech_ml_dataset_tech_v3_dataset_io"
"@deps//:ns_techascent_tech_ml_dataset_tech_v3_dataset_missing"]}}}}
46 changes: 46 additions & 0 deletions examples/stress/test/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#autogenerated, do not edit
package(default_visibility = ["//visibility:public"])
load("@rules_clojure//:rules.bzl", "clojure_library", "clojure_test")

clojure_library(name = "fipp_test",
deps = ["@deps//:ns_fipp_fipp_fipp_edn","@deps//:org_clojure_clojure"],
resources = ["fipp_test.clj"],
resource_strip_prefix = "test")

clojure_test(name = "fipp_test.test",
test_ns = "fipp-test",
deps = [":fipp_test"])

clojure_library(name = "ham_fisted_test",
deps = ["@deps//:ns_com_cnuernber_ham_fisted_ham_fisted_api","@deps//:org_clojure_clojure"],
resources = ["ham_fisted_test.clj"],
resource_strip_prefix = "test")

clojure_test(name = "ham_fisted_test.test",
test_ns = "ham-fisted-test",
deps = [":ham_fisted_test"])

clojure_library(name = "ml_dataset_test",
deps = ["@deps//:ns_techascent_tech_ml_dataset_tech_v3_dataset","@deps//:org_clojure_clojure"],
resources = ["ml_dataset_test.clj"],
resource_strip_prefix = "test")

clojure_test(name = "ml_dataset_test.test",
test_ns = "ml-dataset-test",
deps = [":ml_dataset_test"])

clojure_library(name = "tools_deps_alpha_test",
deps = ["@deps//:ns_org_clojure_tools_deps_alpha_clojure_tools_deps_alpha","@deps//:org_clojure_clojure"],
resources = ["tools_deps_alpha_test.clj"],
resource_strip_prefix = "test")

clojure_test(name = "tools_deps_alpha_test.test",
test_ns = "tools-deps-alpha-test",
deps = [":tools_deps_alpha_test"])

clojure_library(name = "__clj_lib",
deps = [":fipp_test",":ham_fisted_test",":ml_dataset_test",":tools_deps_alpha_test"])

filegroup(name = "__clj_files",
srcs = ["fipp_test.clj","ham_fisted_test.clj","ml_dataset_test.clj","tools_deps_alpha_test.clj"],
data = [])
5 changes: 5 additions & 0 deletions examples/stress/test/fipp_test.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(ns fipp-test
(:require [fipp.edn :as fipp]))

(defn main- [& args]
(fipp/pprint [1 2 3]))
5 changes: 5 additions & 0 deletions examples/stress/test/ham_fisted_test.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(ns ham-fisted-test
(:require ham-fisted.api))

(defn main- [& args]
(println "hello"))
5 changes: 5 additions & 0 deletions examples/stress/test/ml_dataset_test.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(ns ml-dataset-test
(:require [tech.v3.dataset :as ds]))

(defn main- [& args]
(println "hello"))
5 changes: 5 additions & 0 deletions examples/stress/test/tools_deps_alpha_test.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(ns tools-deps-alpha-test
(:require [clojure.tools.deps.alpha :as tools.deps]))

(defn main- [& args]
(println "hello"))
Loading