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

Snoble/fix for linux #1

Closed
wants to merge 2 commits into from
Closed
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
2 changes: 1 addition & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ load("@rules_graal//graal:graal_bindist.bzl", "graal_bindist_repository")

graal_bindist_repository(
name = "graal",
version = "19.0.0",
version = "19.3.1",
)

git_repository(
Expand Down
64 changes: 64 additions & 0 deletions graal/graal.bzl
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain")
load(
"@bazel_tools//tools/build_defs/cc:action_names.bzl",
"ASSEMBLE_ACTION_NAME",
"CPP_COMPILE_ACTION_NAME",
"CPP_LINK_DYNAMIC_LIBRARY_ACTION_NAME",
"CPP_LINK_EXECUTABLE_ACTION_NAME",
"CPP_LINK_STATIC_LIBRARY_ACTION_NAME",
"C_COMPILE_ACTION_NAME",
"OBJCPP_COMPILE_ACTION_NAME",
"OBJC_COMPILE_ACTION_NAME",
)

def _graal_binary_implementation(ctx):
graal_attr = ctx.attr._graal
graal_inputs, _, _ = ctx.resolve_command(tools = [graal_attr])
Expand All @@ -9,11 +22,55 @@ def _graal_binary_implementation(ctx):
if JavaInfo in dep
])

cc_toolchain = find_cpp_toolchain(ctx)
feature_configuration = cc_common.configure_features(
ctx = ctx,
cc_toolchain = cc_toolchain,
requested_features = ctx.features,
unsupported_features = ctx.disabled_features,
)
c_compiler_path = cc_common.get_tool_for_action(
feature_configuration = feature_configuration,
action_name = C_COMPILE_ACTION_NAME,
)
ld_executable_path = cc_common.get_tool_for_action(
feature_configuration = feature_configuration,
action_name = CPP_LINK_EXECUTABLE_ACTION_NAME,
)
ld_static_lib_path = cc_common.get_tool_for_action(
feature_configuration = feature_configuration,
action_name = CPP_LINK_STATIC_LIBRARY_ACTION_NAME,
)
ld_dynamic_lib_path = cc_common.get_tool_for_action(
feature_configuration = feature_configuration,
action_name = CPP_LINK_DYNAMIC_LIBRARY_ACTION_NAME,
)

tool_paths = [c_compiler_path, ld_executable_path, ld_static_lib_path, ld_dynamic_lib_path]
path_set = {}
for tool_path in tool_paths:
tool_dir, _, _ = tool_path.rpartition("/")
path_set[tool_dir] = None

paths = sorted(path_set.keys())
if ctx.configuration.host_path_separator == ":":
# HACK: ":" is a proxy for a UNIX-like host.
# The tools returned above may be bash scripts that reference commands
# in directories we might not otherwise include. For example,
# on macOS, wrapped_ar calls dirname.
if "/bin" not in path_set:
paths.append("/bin")
if "/usr/bin" not in path_set:
paths.append("/usr/bin")
env = {}
env["PATH"] = ctx.configuration.host_path_separator.join(paths)

args = ctx.actions.args()
args.add("--no-server")
args.add("-cp", ":".join([f.path for f in classpath_depset.to_list()]))
args.add("-H:Class=%s" % ctx.attr.main_class)
args.add("-H:Name=%s" % ctx.outputs.bin.path)
args.add("-H:CCompilerPath=%s" % c_compiler_path)

if len(ctx.attr.native_image_features) > 0:
args.add("-H:Features={entries}".format(entries=",".join(ctx.attr.native_image_features)))
Expand All @@ -25,11 +82,13 @@ def _graal_binary_implementation(ctx):
args.add("-H:ReflectionConfigurationFiles={path}".format(path=ctx.file.reflection_configuration.path))
classpath_depset = depset([ctx.file.reflection_configuration], transitive=[classpath_depset])


ctx.actions.run(
inputs = classpath_depset,
outputs = [ctx.outputs.bin],
arguments = [args],
executable = graal,
env = env,
)

return [DefaultInfo(
Expand Down Expand Up @@ -58,10 +117,15 @@ graal_binary = rule(
allow_files = True,
executable = True,
),
"_cc_toolchain": attr.label(
default = Label("@bazel_tools//tools/cpp:current_cc_toolchain")
),
"data": attr.label_list(allow_files = True),
},
outputs = {
"bin": "%{name}-bin",
},
executable = True,
fragments = ["cpp"],
)

63 changes: 45 additions & 18 deletions graal/graal_bindist.bzl
Original file line number Diff line number Diff line change
@@ -1,32 +1,56 @@
_graal_urls = [
"https:/oracle/graal/releases/download/vm-{version}/graalvm-ce-{platform}-{version}.tar.gz",
]

_native_image_urls = [
"https:/oracle/graal/releases/download/vm-{version}/native-image-installable-svm-{platform}-{version}.jar"
]

_graal_archive_internal_prefixs = {
"darwin-amd64": "graalvm-ce-{version}/Contents/Home",
"linux-amd64": "graalvm-ce-{version}",
"darwin-amd64": "graalvm-ce-java{java_version}-{version}/Contents/Home",
"linux-amd64": "graalvm-ce-java{java_version}-{version}",
}

_graal_version_configs = {
"19.0.0": {
"urls": ["https:/oracle/graal/releases/download/vm-{version}/graalvm-ce-{platform}-{version}.tar.gz"],
"sha": {
"darwin-amd64": "fc652566e61b9b774c120da1aea0ae3e28f198d55a297524dcc97b9a83525a79",
"linux-amd64": "7ad124cdb19cbaa962f6d2f26d1e3eccfeb93afabbf8e81cb65976519f15730c",
"8": {
"darwin-amd64": "fc652566e61b9b774c120da1aea0ae3e28f198d55a297524dcc97b9a83525a79",
"linux-amd64": "7ad124cdb19cbaa962f6d2f26d1e3eccfeb93afabbf8e81cb65976519f15730c",
},
},
},
"19.3.1": {
"urls": ["https:/graalvm/graalvm-ce-builds/releases/download/vm-{version}/graalvm-ce-java{java_version}-{platform}-{version}.tar.gz"],
"sha": {
"8": {
"darwin-amd64": "eba3765174f0279ae2dc57c84fc0eb324da778dbfdcc03c6fa8381fe3728aef9",
"linux-amd64": "815385a1c35a1db54b9b9622059c9e8e5155460f65c3d713e55d3a84222c9194",
},
"11": {
"darwin-amd64": "b3ea6cf6545332f667b2cc742bbff9949d47e49eecea06334d14f0b69aa1a3f3",
"linux-amd64": "691f0577c75c4ba0fb50916087925e6eb8a5a73de51994a37eee022d1e2c9e7d",
},
},
}
}

_graal_native_image_version_configs = {
"19.0.0": {
"urls": ["https:/oracle/graal/releases/download/vm-{version}/native-image-installable-svm-{platform}-{version}.jar"],
"sha": {
"darwin-amd64": "4fa035b31cfd3d86d464e9a67b652c69a0cceb88c6b2f2ce629c55ca2113c786",
"linux-amd64": "1c794a3c038f4e6bb90542cf13ba3c6c793dcd193462bf56b8713fd24386e344",
"8": {
"darwin-amd64": "4fa035b31cfd3d86d464e9a67b652c69a0cceb88c6b2f2ce629c55ca2113c786",
"linux-amd64": "1c794a3c038f4e6bb90542cf13ba3c6c793dcd193462bf56b8713fd24386e344",
},
},
},
"19.3.1": {
"urls": ["https:/graalvm/graalvm-ce-builds/releases/download/vm-{version}/native-image-installable-svm-java{java_version}-{platform}-{version}.jar"],
"sha": {
"8": {
"darwin-amd64": "266d295456dfc588fae52ef2c26cd7e745e6fa0681271e677cad2dd9a1b09461",
"linux-amd64": "3fd2e5b5299c8ce7c939235b4d01df990aeb236f127f98fbf19b588c521793fa",
},
"11": {
"darwin-amd64": "6bd2bace9773a2ac7ff8182a36f84507678e71f94bf3f0c4646a091100644e13",
"linux-amd64": "fef2e2c71a5408855026e022ae15fda50cb52769aa7d0ec008837f49196ee16a",
},
},
}
}

def _get_platform(ctx):
Expand All @@ -40,15 +64,17 @@ def _get_platform(ctx):
def _graal_bindist_repository_impl(ctx):
platform = _get_platform(ctx)
version = ctx.attr.version
java_version = ctx.attr.java_version
format_args = {
"version": version,
"platform": platform,
"java_version": java_version,
}

#Download graal
config = _graal_version_configs[version]
sha = config["sha"][platform]
urls = [url.format(**format_args) for url in _graal_urls]
sha = config["sha"][java_version][platform]
urls = [url.format(**format_args) for url in config["urls"]]
archive_internal_prefix = _graal_archive_internal_prefixs[platform].format(**format_args)

ctx.download_and_extract(
Expand All @@ -59,8 +85,8 @@ def _graal_bindist_repository_impl(ctx):

# download native image
native_image_config = _graal_native_image_version_configs[version]
native_image_sha = native_image_config["sha"][platform]
native_image_urls = [url.format(**format_args) for url in _native_image_urls]
native_image_sha = native_image_config["sha"][java_version][platform]
native_image_urls = [url.format(**format_args) for url in native_image_config["urls"]]

ctx.download(
url = native_image_urls,
Expand All @@ -78,6 +104,7 @@ def _graal_bindist_repository_impl(ctx):
graal_bindist_repository = repository_rule(
attrs = {
"version": attr.string(mandatory = True),
"java_version": attr.string(mandatory = True),
},
implementation = _graal_bindist_repository_impl,
)