Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: get rid of "python" in flavor of rules_python #56

Merged
merged 5 commits into from
Sep 20, 2024
Merged
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
Expand Up @@ -3,7 +3,7 @@ build:nix --host_platform=@rules_nixpkgs_core//platforms:host
build:nix --host_cxxopt=-std=c++14
build:nix --cxxopt=c++14
# bazel run @rules_bazel_integration_test//tools:update_deleted_packages
build:nix --deleted_packages=examples/elm-binary,examples/elm-proto,examples/elm-proto/foo,examples/elm-test,examples/elm-todomvc
query:nix --deleted_packages=examples/elm-binary,examples/elm-proto,examples/elm-proto/foo,examples/elm-test,examples/elm-todomvc
build:nix --deleted_packages=examples/elm-binary,examples/elm-binary/nix-toolchains,examples/elm-proto,examples/elm-proto/foo,examples/elm-proto/nix-toolchains,examples/elm-test,examples/elm-test/nix-toolchains,examples/elm-todomvc,examples/elm-todomvc/nix-toolchains
query:nix --deleted_packages=examples/elm-binary,examples/elm-binary/nix-toolchains,examples/elm-proto,examples/elm-proto/foo,examples/elm-proto/nix-toolchains,examples/elm-test,examples/elm-test/nix-toolchains,examples/elm-todomvc,examples/elm-todomvc/nix-toolchains

build:ci --config=nix --test_output=all --disk_cache=~/.bazel-disk-cache
2 changes: 2 additions & 0 deletions .github/workflows/release_prep.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ load("@rules_elm//elm:dependencies.bzl", "elm_dependencies")
elm_dependencies()
load("@aspect_rules_js//js:repositories.bzl", "rules_js_dependencies")
rules_js_dependencies() # rules_elm depends on rules_js
load("@rules_python//python:repositories.bzl", "py_repositories")
py_repositories() # rules_elm depends on rules_python
load("@rules_elm//elm:repositories.bzl", "elm_register_toolchains")
elm_register_toolchains()
load("@rules_elm_npm//:repositories.bzl", elm_npm_repositories = "npm_repositories")
Expand Down
3 changes: 2 additions & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ bazel_dep(name = "platforms", version = "0.0.10")
bazel_dep(name = "bazel_skylib", version = "1.7.1")
bazel_dep(name = "aspect_bazel_lib", version = "2.7.7")
bazel_dep(name = "rules_nodejs", version = "6.2.0")
bazel_dep(name = "cgrindel_bazel_starlib", version = "0.20.2")
bazel_dep(name = "rules_proto", version = "6.0.2")
bazel_dep(name = "protobuf", version = "27.1", repo_name = "com_google_protobuf")
bazel_dep(name = "rules_python", version = "0.35.0")

bazel_dep(name = "cgrindel_bazel_starlib", version = "0.20.2", dev_dependency = True)
bazel_dep(name = "rules_nixpkgs_core", version = "0.12.0", dev_dependency = True)
bazel_dep(name = "rules_bazel_integration_test", version = "0.24.1", dev_dependency = True)

Expand Down
29 changes: 13 additions & 16 deletions elm/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,8 @@ def _do_elm_make(

ctx.actions.run(
mnemonic = "Elm",
executable = "python",
executable = ctx.executable._compile,
arguments = [
ctx.files._compile[0].path,
compilation_mode,
toolchain_elm_files_list[0].path,
elm_json.path,
Expand Down Expand Up @@ -146,11 +145,12 @@ elm_binary = rule(
mandatory = True,
),
"_compile": attr.label(
allow_single_file = True,
default = Label("@rules_elm//elm/private:compile.py"),
cfg = "exec",
default = Label("@rules_elm//elm/private:compile"),
executable = True,
),
"_uglifyjs": attr.label(
cfg = "host",
cfg = "exec",
default = Label("@rules_elm//tools/uglifyjs:bin"),
executable = True,
),
Expand Down Expand Up @@ -248,9 +248,8 @@ def _elm_test_impl(ctx):
main_file = ctx.actions.declare_file(main_filename)
ctx.actions.run(
mnemonic = "ElmGenTest",
executable = "python",
executable = ctx.executable._generate_test_main,
arguments = [
ctx.files._generate_test_main[0].path,
module_name,
tests_found_file.path,
main_file.path,
Expand Down Expand Up @@ -315,20 +314,18 @@ elm_test = rule(
mandatory = True,
),
"_compile": attr.label(
allow_single_file = True,
default = Label("@rules_elm//elm/private:compile.py"),
executable = True,
cfg = "exec",
default = Label("@rules_elm//elm/private:compile"),
),
"_generate_test_main": attr.label(
allow_single_file = True,
default = Label(
"@rules_elm//elm/private:generate_test_main.py",
),
executable = True,
cfg = "exec",
default = Label("@rules_elm//elm/private:generate_test_main"),
),
"_node_test_runner": attr.label(
providers = [_ElmLibrary],
default = Label(
"@com_github_rtfeldman_node_test_runner//:node_test_runner",
),
default = Label("@com_github_rtfeldman_node_test_runner//:node_test_runner"),
),
"_tests_finder": attr.label(
allow_single_file = True,
Expand Down
8 changes: 8 additions & 0 deletions elm/dependencies.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ def elm_dependencies():
url = "https://github.com/bazelbuild/rules_proto/releases/download/6.0.2/rules_proto-6.0.2.tar.gz",
)

if not native.existing_rule("rules_python"):
http_archive(
name = "rules_python",
sha256 = "be04b635c7be4604be1ef20542e9870af3c49778ce841ee2d92fcb42f9d9516a",
strip_prefix = "rules_python-0.35.0",
url = "https://github.com/bazelbuild/rules_python/releases/download/0.35.0/rules_python-0.35.0.tar.gz",
)

if not native.existing_rule("com_google_protobuf"):
http_archive(
name = "com_google_protobuf",
Expand Down
21 changes: 17 additions & 4 deletions elm/private/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
exports_files([
"compile.py",
"generate_test_main.py",
])
load("@rules_python//python:defs.bzl", "py_binary")

py_binary(
name = "compile",
srcs = [
"compile.py"
],
visibility = ["//:__subpackages__"],
)

py_binary(
name = "generate_test_main",
srcs = [
"generate_test_main.py"
],
visibility = ["//:__subpackages__"],
)

filegroup(
name = "all_files",
Expand Down
11 changes: 6 additions & 5 deletions examples/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ rules_elm_integration_test_each_bazel(
bazel_binaries = bazel_binaries,
workspace_path = "elm-binary",
bazel_cmd = "build :main",
expected_output = "INFO: Build completed successfully, 4 total actions",
expected_output = "INFO: Build completed successfully, (8|7) total actions",
# sometimes it fails with an error:
# 0.19.1/d.dat: openBinaryFile: resource busy (file is locked)
flaky = True,
)

rules_elm_integration_test_each_bazel(
Expand All @@ -48,9 +51,7 @@ of `List` and `Maybe` do not work without it.

If you modified your elm.json by hand, try to change it back! And if you are
having trouble getting back to a working elm.json, it may be easier to delete it
and use `elm init` to start fresh.

ERROR:""",
and use `elm init` to start fresh.""",
)

rules_elm_integration_test_each_bazel(
Expand All @@ -59,7 +60,7 @@ rules_elm_integration_test_each_bazel(
test_runner = ":output_match_runner",
workspace_path = "elm-todomvc",
bazel_cmd = "build :bin",
expected_output = """INFO: Build completed successfully, 4 total actions""",
expected_output = """INFO: Build completed successfully, (7|8) total actions""",
)

rules_elm_integration_test_each_bazel(
Expand Down
2 changes: 2 additions & 0 deletions examples/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def rules_elm_integration_test_each_bazel(
bazel_cmd,
expected_output,
test_runner = ":output_match_runner",
**kwargs,
):
for config in _configs:
for bazel_binary_name in bazel_binaries:
Expand All @@ -70,4 +71,5 @@ def rules_elm_integration_test_each_bazel(
# https://github.com/bazelbuild/bazel/issues/1990
"no-sandbox",
],
**kwargs,
)
14 changes: 0 additions & 14 deletions examples/elm-binary/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,18 +1,4 @@
load("@rules_elm//elm:defs.bzl", "elm_binary")
load("@rules_nodejs//nodejs:toolchain.bzl", "nodejs_toolchain")

nodejs_toolchain(
name = "node_toolchain",
node = "@nixpkgs_nodejs//:bin/node",
npm = "@nixpkgs_nodejs//:bin/npm",
)

toolchain(
name = "nixpkgs_nodejs_toolchain",
exec_compatible_with = [ "@rules_nixpkgs_core//constraints:support_nix" ],
toolchain = ":node_toolchain",
toolchain_type = "@rules_nodejs//nodejs:toolchain_type",
)

elm_binary(
name = "main",
Expand Down
11 changes: 9 additions & 2 deletions examples/elm-binary/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ local_path_override(

bazel_dep(name = "rules_nixpkgs_core", version = "0.12.0", dev_dependency = True)
bazel_dep(name = "rules_nodejs", version = "6.2.0")
bazel_dep(name = "rules_python", version = "0.35.0")

elm = use_extension("@rules_elm//elm:extensions.bzl", "elm")
elm.repository(
Expand Down Expand Up @@ -56,13 +57,19 @@ nix_pkg.attr(
attr = "nodejs",
repo = "@nixpkgs",
)

nix_pkg.attr(
name = "nixpkgs_python3",
attr = "python3",
repo = "@nixpkgs",
)
use_repo(
nix_pkg,
"nixpkgs_nodejs",
"nixpkgs_python3",
)

register_toolchains(
"//:nixpkgs_nodejs_toolchain"
"//nix-toolchains:nixpkgs_nodejs_toolchain",
"//nix-toolchains:nixpkgs_python_toolchain",
)

12 changes: 11 additions & 1 deletion examples/elm-binary/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ load("@rules_elm//elm:dependencies.bzl", "elm_dependencies")
elm_dependencies()
load("@aspect_rules_js//js:repositories.bzl", "rules_js_dependencies")
rules_js_dependencies()
load("@rules_python//python:repositories.bzl", "py_repositories")
py_repositories()

_rules_nixpkgs_version = "0.12.0"
strip_prefix = "rules_nixpkgs-%s" % _rules_nixpkgs_version
Expand All @@ -31,7 +33,15 @@ nixpkgs_package(
attribute_path = "nodejs",
repository = "@nixpkgs"
)
register_toolchains("//:nixpkgs_nodejs_toolchain")
nixpkgs_package(
name = "nixpkgs_python3",
attribute_path = "python3",
repository = "@nixpkgs"
)
register_toolchains(
"//nix-toolchains:nixpkgs_nodejs_toolchain",
"//nix-toolchains:nixpkgs_python_toolchain",
)

load("@rules_elm//elm:repositories.bzl", "elm_register_toolchains")
elm_register_toolchains()
Expand Down
36 changes: 36 additions & 0 deletions examples/elm-binary/nix-toolchains/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
load("@rules_nodejs//nodejs:toolchain.bzl", "nodejs_toolchain")
load("@rules_python//python:py_runtime.bzl", "py_runtime")
load("@rules_python//python:py_runtime_pair.bzl", "py_runtime_pair")

nodejs_toolchain(
name = "node_toolchain",
node = "@nixpkgs_nodejs//:bin/node",
npm = "@nixpkgs_nodejs//:bin/npm",
)

toolchain(
name = "nixpkgs_nodejs_toolchain",
exec_compatible_with = [ "@rules_nixpkgs_core//constraints:support_nix" ],
toolchain = ":node_toolchain",
toolchain_type = "@rules_nodejs//nodejs:toolchain_type",
)

py_runtime(
name = "my_py3_runtime",
interpreter = "@nixpkgs_python3//:bin/python",
python_version = "PY3",
)

py_runtime_pair(
name = "my_py_runtime_pair",
py3_runtime = ":my_py3_runtime",
)

toolchain(
name = "nixpkgs_python_toolchain",
exec_compatible_with = [
"@rules_nixpkgs_core//constraints:support_nix"
],
toolchain = ":my_py_runtime_pair",
toolchain_type = "@rules_python//python:toolchain_type",
)
60 changes: 1 addition & 59 deletions examples/elm-proto/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,67 +1,9 @@
load("@rules_elm//proto:defs.bzl",
"elm_proto_library",
"ELM_PROTO_TOOLCHAIN",
"INCOMPATIBLE_ENABLE_PROTO_TOOLCHAIN_RESOLUTION")
load("@rules_elm//proto:elm_proto_toolchain_rule.bzl", "elm_proto_toolchain")
load("@rules_elm//elm:defs.bzl", "elm_test")
load("@rules_nodejs//nodejs:toolchain.bzl", "nodejs_toolchain")
load("@rules_proto//proto:defs.bzl", "proto_library")
load("@rules_proto//proto/private/rules:proto_toolchain_rule.bzl", "proto_toolchain")

nodejs_toolchain(
name = "node_toolchain",
node = "@nixpkgs_nodejs//:bin/node",
npm = "@nixpkgs_nodejs//:bin/npm",
)

toolchain(
name = "nixpkgs_nodejs_toolchain",
exec_compatible_with = [ "@rules_nixpkgs_core//constraints:support_nix" ],
toolchain = ":node_toolchain",
toolchain_type = "@rules_nodejs//nodejs:toolchain_type",
)

proto_toolchain(
name = "nixpkgs_protoc_toolchain",
proto_compiler = "@nixpkgs_protobuf//:bin/protoc",
visibility = ["//visibility:public"],
)

toolchain(
name = "nixpkgs_protobuf_toolchain",
toolchain_type = "@rules_proto//proto:toolchain_type",
exec_compatible_with = [
"@rules_nixpkgs_core//constraints:support_nix"
],
toolchain = ":nixpkgs_protoc_toolchain",
)

elm_proto_deps = [
"@elm_package_eriktim_elm_protocol_buffers",
"@elm_package_anmolitor_elm_protoc_types",
"@elm_package_danfishgold_base64_bytes",
"@elm_package_elm_file",
"@elm_package_elm_http",
"@elm_package_elm_parser",
"@elm_package_anmolitor_elm_protoc_utils",
"@elm_package_rtfeldman_elm_iso8601_date_strings",
]

elm_proto_toolchain(
name = "elm_proto_toolchain_opt_json",
proto_compiler = "@nixpkgs_protobuf//:bin/protoc",
protoc_opts = [
"--elm_opt=json=decode",
],
deps = elm_proto_deps,
)

toolchain(
name = "nixpkgs_elm_protobuf_toolchain",
toolchain_type = ELM_PROTO_TOOLCHAIN,
exec_compatible_with = [ "@rules_nixpkgs_core//constraints:support_nix" ],
toolchain = ":elm_proto_toolchain_opt_json",
)
load("//nix-toolchains:proto_deps.bzl", "elm_proto_deps")

proto_library(
name = "book_proto",
Expand Down
14 changes: 11 additions & 3 deletions examples/elm-proto/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ local_path_override(
bazel_dep(name = "rules_proto", version = "6.0.2")
bazel_dep(name = "rules_nixpkgs_core", version = "0.12.0")
bazel_dep(name = "rules_nodejs", version = "6.2.0")
bazel_dep(name = "rules_python", version = "0.35.0")
bazel_dep(name = "protobuf", version = "27.1", repo_name = "com_google_protobuf")

elm = use_extension("@rules_elm//elm:extensions.bzl", "elm")
Expand Down Expand Up @@ -156,14 +157,21 @@ nix_pkg.attr(
attr = "protobuf",
repo = "@nixpkgs",
)
nix_pkg.attr(
name = "nixpkgs_python3",
attr = "python3",
repo = "@nixpkgs",
)
use_repo(
nix_pkg,
"nixpkgs_nodejs",
"nixpkgs_protobuf",
"nixpkgs_python3",
)

register_toolchains(
"//:nixpkgs_nodejs_toolchain",
"//:nixpkgs_elm_protobuf_toolchain",
"//:nixpkgs_protobuf_toolchain",
"//nix-toolchains:nixpkgs_nodejs_toolchain",
"//nix-toolchains:nixpkgs_elm_protobuf_toolchain",
"//nix-toolchains:nixpkgs_protobuf_toolchain",
"//nix-toolchains:nixpkgs_python_toolchain",
)
Loading