Skip to content

Commit

Permalink
Cleanup graal_native_binary rule
Browse files Browse the repository at this point in the history
Summary:
Updates the output type and uses JavaInfo instead of traversing the files
in the DefaultInfo provider.

Test Plan: `graal_java_fib_aot` still builds successfully.

Reviewers: zasgar, jamesbartlett

Reviewed By: jamesbartlett

Signed-off-by: Vihang Mehta <[email protected]>

Differential Revision: https://phab.corp.pixielabs.ai/D12853

GitOrigin-RevId: aed1778f3b613e41884cf8e50f633659e4977ea5
  • Loading branch information
vihangm authored and copybaranaut committed Jan 20, 2023
1 parent 421df43 commit c70fd99
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 37 deletions.
32 changes: 11 additions & 21 deletions bazel/graal/rules.bzl → bazel/graal.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,19 @@
def _graal_native_binary_impl(ctx):
cc_toolchain_info = ctx.toolchains["@bazel_tools//tools/cpp:toolchain_type"].cc

# TODO(james): this is a bit of a hack because bazel's JavaInfo doesn't currently have starlark definitions,
# so its hard to traverse.
default_info = ctx.attr.java_binary[DefaultInfo]
jar = None
for file in default_info.files.to_list():
if file.path.endswith(".jar"):
jar = file
break
if jar == None:
fail("no .jar file in java_binary rule output")
if len(ctx.attr.java_binary[JavaInfo].java_outputs) == 0:
fail("no jars in java_binary rule output")

out_name = ctx.attr.output_name
if out_name == "":
out_name = ctx.attr.name

out = ctx.actions.declare_file(out_name)
if len(ctx.attr.java_binary[JavaInfo].java_outputs) > 1:
fail("more than one output jar in java_binary rule output")

jar = ctx.attr.java_binary[JavaInfo].java_outputs[0].class_jar
graal_runtime = ctx.attr.graal_runtime[java_common.JavaRuntimeInfo]
args = [
"-cp",
jar.path,
"-o",
out.path,
ctx.outputs.output_name.path,
"--native-compiler-path=" + cc_toolchain_info.compiler_executable,
# Add /usr/bin as prefix, so that `native-image` can find ld.
# The real solution would be to get `native-image` to work with the combination of lld and gcc.
Expand All @@ -49,7 +39,7 @@ def _graal_native_binary_impl(ctx):
] + ctx.attr.extra_args

ctx.actions.run(
outputs = [out],
outputs = [ctx.outputs.output_name],
inputs = depset(
[jar],
transitive = [
Expand All @@ -63,8 +53,8 @@ def _graal_native_binary_impl(ctx):

return [
DefaultInfo(
files = depset([out]),
executable = out,
files = depset([ctx.outputs.output_name]),
executable = ctx.outputs.output_name,
),
]

Expand All @@ -79,9 +69,9 @@ graal_native_binary = rule(
allow_files = True,
),
"java_binary": attr.label(
providers = [JavaInfo, DefaultInfo],
providers = [JavaInfo],
),
"output_name": attr.string(),
"output_name": attr.output(mandatory = True),
},
toolchains = [
"@bazel_tools//tools/cpp:toolchain_type",
Expand Down
15 changes: 0 additions & 15 deletions bazel/graal/BUILD.bazel

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
load("@io_bazel_rules_docker//container:image.bzl", "container_image")
load("@io_bazel_rules_docker//java:image.bzl", "java_image")
load("@rules_java//java:defs.bzl", "java_binary")
load("//bazel:graal.bzl", "graal_native_binary")
load("//bazel:pl_build_system.bzl", "pl_cc_binary")
load("//bazel:toolchain_transitions.bzl", "java_graal_binary")
load("//bazel/graal:rules.bzl", "graal_native_binary")
load("//src/stirling/source_connectors/perf_profiler/testing:testing.bzl", "jdk_names")

package(default_visibility = ["//src/stirling:__subpackages__"])
Expand Down

0 comments on commit c70fd99

Please sign in to comment.