Skip to content

Commit

Permalink
Avoid compiling damlc twice (#8428)
Browse files Browse the repository at this point in the history
This only compiles `damlc-bootstrap` as a Haskell binary and `damlc` is
a simple symlink with additional runfiles.

We now need to define `damlc@ghci` manually since it is no longer
defined automatically. The manual definition was tested with

```
$ bazel run //:damlc@ghci --define ghci_data=True
> :main ide -d
```

changelog_begin
changelog_end

Co-authored-by: Andreas Herrmann <[email protected]>
  • Loading branch information
aherrmann-da and aherrmann authored Jan 7, 2021
1 parent 6d21400 commit fa45a58
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 28 deletions.
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

0 comments on commit fa45a58

Please sign in to comment.