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

Avoid compiling damlc twice #8428

Merged
merged 1 commit into from
Jan 7, 2021
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
42 changes: 42 additions & 0 deletions bazel_tools/runfiles/defs.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

load("@os_info//:os_info.bzl", "is_windows")

def _add_data_impl(ctx):
executable = ctx.actions.declare_file(
ctx.label.name + (".exe" if is_windows else ""),
)
ctx.actions.symlink(
output = executable,
target_file = ctx.executable.executable,
is_executable = True,
)

runfiles = ctx.runfiles(files = [ctx.executable.executable] + ctx.files.data)
runfiles = runfiles.merge(ctx.attr.executable[DefaultInfo].default_runfiles)
for data_dep in ctx.attr.data:
runfiles = runfiles.merge(data_dep[DefaultInfo].default_runfiles)

return [DefaultInfo(
executable = executable,
files = depset(direct = [executable]),
runfiles = runfiles,
)]

add_data = rule(
_add_data_impl,
attrs = {
"executable": attr.label(
executable = True,
cfg = "target",
doc = "Create a symlink to this executable",
),
"data": attr.label_list(
allow_files = True,
doc = "Add these data files to the executable's runfiles",
),
},
executable = True,
doc = "Creates a new target for the given executable with additional runfiles.",
)
53 changes: 25 additions & 28 deletions compiler/damlc/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,42 +1,39 @@
# Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

load("//bazel_tools:haskell.bzl", "da_haskell_binary", "da_haskell_library", "da_haskell_test")
load("//bazel_tools:haskell.bzl", "da_haskell_binary", "da_haskell_library", "da_haskell_repl", "da_haskell_test")
load("//rules_daml:daml.bzl", "daml_doc_test")
load("@os_info//:os_info.bzl", "is_windows")
load("//bazel_tools/packaging:packaging.bzl", "package_app")
load("//bazel_tools/runfiles:defs.bzl", "add_data")
load(":util.bzl", "ghc_pkg")

da_haskell_binary(
damlc_data = [
"//compiler/damlc/daml-ide-core:dlint.yaml",
"@static_asset_d3plus//:js/d3.min.js",
"@static_asset_d3plus//:js/d3plus.min.js",
ghc_pkg,
"//compiler/damlc:ghcversion",
"//compiler/damlc:hpp",
"//compiler/damlc/pkg-db",
"//compiler/damlc/stable-packages",
"//compiler/repl-service/server:repl_service_jar",
"//compiler/scenario-service/server:scenario_service_jar",
]

add_data(
name = "damlc",
srcs = ["exe/Main.hs"],
data = damlc_data,
executable = ":damlc-bootstrap",
visibility = ["//visibility:public"],
)

# We need to tell the linker to statically link pthread on Windows
# otherwise the library is not found at runtime.
compiler_flags = [
"-optl-static",
"-optl-pthread",
] if is_windows else [],
data = [
"//compiler/damlc/daml-ide-core:dlint.yaml",
"@static_asset_d3plus//:js/d3.min.js",
"@static_asset_d3plus//:js/d3plus.min.js",
ghc_pkg,
"//compiler/damlc:ghcversion",
"//compiler/damlc:hpp",
"//compiler/damlc/pkg-db",
"//compiler/damlc/stable-packages",
"//compiler/repl-service/server:repl_service_jar",
"//compiler/scenario-service/server:scenario_service_jar",
],
hackage_deps = [
"base",
],
src_strip_prefix = "exe",
da_haskell_repl(
name = "damlc@ghci",
data = damlc_data,
repl_ghci_commands = [":m Main"],
visibility = ["//visibility:public"],
deps = [
":damlc-lib",
],
deps = [":damlc-bootstrap"],
)

genrule(
Expand Down