Skip to content

Commit

Permalink
Update to bazel-0.27 (digital-asset#1957)
Browse files Browse the repository at this point in the history
* Bazel: 0.24.0 -> 0.27.0

* Update rules_haskell for Bazel 0.27 compatibility

* Update bazel-deps and bazel-watcher

* Windows escape JVM flags

* load commands at top of .bzl file

Bazel 0.27 no longer allows load commands that are not at the beginning
of the file.

* Update Bazel rules

* subpackage boundary

* native is not defined in BUILD files

* yarn: @bazel/hide-bazel-files

Seems to be required since latest rules_nodejs version. Otherwise, yarn
fails with errors about existing BUILD or BUILD.bazel files.

* grpc-java plugin visibility

* Update fat_cc_library

* Nix Python3 toolchain

* Iteration over depset

* dev_env_package: Create symlinks one level deeper

To prevent symlinking the BUILD file as well. The nested BUILD file
confuses Bazel as of 0.27 and rules_nodejs cannot find the node
executable anymore.

* Update rules_nodejs

* Add managed_directories for node_modules

* hie-bios: Extract bazel-genfiles from bazel info

Bazel 0.27 changed the genfiles location which breaks the hie-core test
on macOS.

* update cc_wrapper to Bazel 0.27

* bazel info -> bazel info bazel-genfiles

* Fix typo in BUILD

Co-Authored-By: Stefano Baghino <43749967+stefanobaghino-da@users.noreply.github.com>
  • Loading branch information
2 people authored and mergify[bot] committed Jul 5, 2019
1 parent 79d88a4 commit df7bff6
Show file tree
Hide file tree
Showing 34 changed files with 913 additions and 286 deletions.
12 changes: 3 additions & 9 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ build:darwin --disk_cache=.bazel-cache
# This will become the default in a future Bazel release.
build --experimental_strict_action_env

# Required for node_modules trees generated by yarn_install.
common --experimental_allow_incremental_repository_updates

# Print test output of failed test.
# Set --test_output=streamed to get the output of all tests in real time.
# Note, this will force tests to run locally and sequentially.
Expand Down Expand Up @@ -89,15 +92,6 @@ build:darwin --protocopt=--include_source_info
# https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/compiler/command_line_interface.cc#L1363
#build:windows --protocopt=--include_source_info

# Bazel 0.24 introduced the new flag --incompatible_windows_escape_jvm_flags
# and modified its Java launcher mechanism. rules_scala needs to be patched
# to support this. See `bazel_tools/scala-escape-jvmflags.patch`.
# Without this patch we get the following error on Windows:
# `LAUNCHER ERROR: Cannot find key "escape_jvmflags" from launch data.`
# This patch assumes `--noincompatible_windows_escape_jvm_flags`.
# See https://github.com/bazelbuild/bazel/pull/7490
build:windows --noincompatible_windows_escape_jvm_flags

# Some tools used in tests, like postgres CLI, require cmd.exe which can be located by them
# using ComSpec environment variable. By default it's not passed from Bazel client environment.
test:windows --test_env=ComSpec
Expand Down
20 changes: 4 additions & 16 deletions .hie-bios
Original file line number Diff line number Diff line change
@@ -1,26 +1,14 @@
#!/bin/sh
cat "$HIE_BIOS_ARGS" | sed "s/'//g" | sed "s/-qg//g" | sed "s/+RTS.*-RTS//" | sed "s|/bazel-out|bazel-out|g" | sed "s/-fexternal-interpreter//g"

BAZEL_DIR=""
case $(uname) in
Linux)
BAZEL_DIR=k8-fastbuild
;;
Darwin)
BAZEL_DIR=darwin-fastbuild
;;
*)
echo "Unsupported OS: $(uname)"
exit 1
;;
esac
BAZEL_GENFILES="$(bazel info bazel-genfiles)"

# For now we hardcode include paths as Bazel passes the list of files explicitly
# and does not use include paths so we cannot get it from the GHCi invocation.
echo \
-ibazel-out/$BAZEL_DIR/genfiles \
-ibazel-out/$BAZEL_DIR/genfiles/compiler/scenario-service/protos \
-ibazel-out/$BAZEL_DIR/genfiles/daml-lf/archive \
-i"${BAZEL_GENFILES}" \
-i"${BAZEL_GENFILES}"/compiler/scenario-service/protos \
-i"${BAZEL_GENFILES}"/daml-lf/archive \
-icompiler/daml-lf-ast/src \
-icompiler/daml-lf-proto/src \
-icompiler/daml-lf-reader/src \
Expand Down
25 changes: 25 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package(default_visibility = ["//:__subpackages__"])

load("@bazel_tools//tools/python:toolchain.bzl", "py_runtime_pair")
load(
"@io_tweag_rules_haskell//haskell:haskell.bzl",
"haskell_toolchain",
Expand Down Expand Up @@ -58,6 +59,30 @@ c2hs_toolchain(
c2hs = "@haskell_c2hs//:bin",
)

#
# Python toolchain
#

py_runtime(
name = "nix_python3_runtime",
interpreter = "@python3_nix//:bin/python",
python_version = "PY3",
) if not is_windows else None

py_runtime_pair(
name = "nix_python_runtime_pair",
py3_runtime = ":nix_python3_runtime",
) if not is_windows else None

toolchain(
name = "nix_python_toolchain",
exec_compatible_with = [
"@io_tweag_rules_haskell//haskell/platforms:nixpkgs",
],
toolchain = ":nix_python_runtime_pair",
toolchain_type = "@bazel_tools//tools/python:toolchain_type",
) if not is_windows else None

filegroup(
name = "node_modules",
srcs = glob(["node_modules/**/*"]),
Expand Down
21 changes: 18 additions & 3 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
workspace(name = "com_github_digital_asset_daml")
workspace(
name = "com_github_digital_asset_daml",
managed_directories = {
"@npm": ["node_modules"],
"@daml_extension_deps": ["daml-foundations/daml-tools/daml-extension/node_modules"],
"@navigator_frontend_deps": ["navigator/frontend/node_modules"],
},
)

load("//:util.bzl", "hazel_ghclibs", "hazel_github", "hazel_github_external", "hazel_hackage")

Expand Down Expand Up @@ -735,8 +742,7 @@ load("@npm//:install_bazel_dependencies.bzl", "install_bazel_dependencies")

install_bazel_dependencies()

# Setup TypeScript toolchain
load("@build_bazel_rules_typescript//:defs.bzl", "ts_setup_workspace")
load("@npm_bazel_typescript//:defs.bzl", "ts_setup_workspace")

ts_setup_workspace()

Expand Down Expand Up @@ -795,6 +801,15 @@ load("@com_github_bazelbuild_buildtools//buildifier:deps.bzl", "buildifier_depen

buildifier_dependencies()

nixpkgs_package(
name = "python3_nix",
attribute_path = "python3",
nix_file_deps = common_nix_file_deps,
repositories = dev_env_nix_repos,
)

register_toolchains("//:nix_python_toolchain") if not is_windows else None

nixpkgs_package(
name = "postgresql_nix",
attribute_path = "postgresql",
Expand Down
10 changes: 9 additions & 1 deletion bazel_tools/dev_env_package/dev_env_package.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,15 @@ def _dev_env_package_impl(ctx):
else:
tool_home = "../%s" % ctx.attr.nix_label.name

ctx.symlink(tool_home, ctx.path(ctx.attr.symlink_path))
python = ctx.which("python3")
if python == None:
python = ctx.which("python")
if python == None:
fail("Cannot find python3 executable")
mklinks = ctx.path(Label("//bazel_tools/dev_env_package:dev_env_package.py"))
res = ctx.execute([python, mklinks, tool_home, ctx.attr.symlink_path])
if res.return_code != 0:
fail("Failed to create symlinks\nstdout:{}\nstderr:{}\n".format(res.stdout, res.stderr))

build_path = ctx.path("BUILD")
build_content = _dev_env_package_build_template.format(
Expand Down
33 changes: 33 additions & 0 deletions bazel_tools/dev_env_package/dev_env_package.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env python3
# Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
# SPDX-License-Identifier: Apache-2.0


import argparse
import os


def main():
parser = argparse.ArgumentParser()
parser.add_argument("source", type=str)
parser.add_argument("destination", type=str)
args = parser.parse_args()

create_symlinks(args.source, args.destination)


def create_symlinks(source_dir, dest_dir):
print(os.getcwd(), source_dir, dest_dir)
os.makedirs(dest_dir, exist_ok=True)
for item in os.listdir(source_dir):
if item in ["BUILD", "BUILD.bazel", "WORKSPACE"]:
# Skip nested BUILD files as they confuse Bazel.
continue
relpath = os.path.relpath(os.path.join(source_dir, item), dest_dir)
print("ln -s {} {}".format(relpath, os.path.join(dest_dir, item)))
os.symlink(relpath, os.path.join(dest_dir, item))


if __name__ == "__main__":
main()

13 changes: 4 additions & 9 deletions bazel_tools/fat_cc_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def _fat_cc_library_impl(ctx):
# For now we assume that we have static PIC libs for all libs.
# It should be possible to extend this but we do not have a need
# for it so far and it would complicate things.
for lib in cc_info.linking_context.libraries_to_link:
for lib in cc_info.linking_context.libraries_to_link.to_list():
static_lib = None
if lib.pic_static_library:
static_lib = lib.pic_static_library
Expand All @@ -28,7 +28,7 @@ def _fat_cc_library_impl(ctx):
static_lib = ctx.outputs.static_library

toolchain = ctx.attr._cc_toolchain[cc_common.CcToolchainInfo]
feature_configuration = cc_common.configure_features(cc_toolchain = toolchain)
feature_configuration = cc_common.configure_features(ctx = ctx, cc_toolchain = toolchain)

compiler = None
if is_darwin:
Expand Down Expand Up @@ -101,13 +101,7 @@ def _fat_cc_library_impl(ctx):
linking_context = new_linking_context,
compilation_context = cc_info.compilation_context,
)
return struct(
# cc is a legacy provider so it needs to be handled differently.
# Hopefully, rules_haskell will stop depending onit at somepoint and
# we can stop providing both cc and CcInfo.
cc = input_lib.cc,
providers = [new_cc_info],
)
return [new_cc_info]

# Shared libraries built with Bazel do not declare their dependencies on other libraries properly.
# Instead that dependency is tracked in Bazel internally. This breaks the GHCi linker if
Expand Down Expand Up @@ -138,6 +132,7 @@ fat_cc_library = rule(
default = [] if is_darwin else ["-Wl,--no-whole-archive"],
),
}),
fragments = ["cpp"],
outputs = {
"dynamic_library": "lib%{name}.dll" if is_windows else "lib%{name}.so",
"static_library": "lib%{name}.a",
Expand Down
16 changes: 16 additions & 0 deletions bazel_tools/grpc-java-plugin-visibility.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
grpc-java now only exposes the protoc plugin indirectly through a toolchain.
However, the current implementation of //bazel_tools.proto.bzl proto_gen
assumes direct access to the protoc plugin label.
https://github.com/grpc/grpc-java/commit/745aa0a2f570d74e7d7fe0c72334c24e21b8ab17
diff --git a/compiler/BUILD.bazel b/compiler/BUILD.bazel
index ef940741d..e50ecb66c 100644
--- a/compiler/BUILD.bazel
+++ b/compiler/BUILD.bazel
@@ -10,6 +10,7 @@ cc_binary(
deps = [
"@com_google_protobuf//:protoc_lib",
],
+ visibility = ["//visibility:public"],
)

java_library(
6 changes: 4 additions & 2 deletions bazel_tools/haskell-windows-library-dirs.patch
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,14 @@ new file mode 100644
index 0000000..ec944e5
--- /dev/null
+++ b/haskell/private/cc_wrapper.bzl
@@ -0,0 +1,50 @@
@@ -0,0 +1,52 @@
+load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain")
+load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "ACTION_NAMES")
+
+def _cc_wrapper_impl(ctx):
+ 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,
Expand Down Expand Up @@ -95,7 +96,8 @@ index 0000000..ec944e5
+ "_cc_toolchain": attr.label(
+ default = Label("@bazel_tools//tools/cpp:current_cc_toolchain"),
+ ),
+ }
+ },
+ fragments = ["cpp"],
+)
+
+def cc_wrapper(name, **kwargs):
Expand Down
2 changes: 1 addition & 1 deletion bazel_tools/hlint.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def _haskell_hlint_aspect_impl(target, ctx):
inputPaths = []
if hasattr(ctx.rule.attr, "srcs"):
for src in ctx.rule.attr.srcs:
for f in src.files:
for f in src.files.to_list():
# We want to only do native Haskell source files, which
# seems to involve ignoring these generated paths
# (the f.is_source almost always returns True)
Expand Down
5 changes: 2 additions & 3 deletions bazel_tools/packaging/packaging.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ def _package_app_impl(ctx):
tools = [ctx.executable.tar, ctx.executable.gzip] if is_windows else [ctx.executable.patchelf, ctx.executable.tar, ctx.executable.gzip]
ctx.actions.run_shell(
outputs = [ctx.outputs.out],
inputs =
[ctx.executable.package_app] + tools +
inputs.to_list(),
tools = [ctx.executable.package_app] + tools,
inputs = inputs.to_list(),
arguments = [args],
progress_message = "Packaging " + ctx.attr.name,
command = """
Expand Down
4 changes: 2 additions & 2 deletions bazel_tools/pom_file.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ MavenInfo = provider(

_EMPTY_MAVEN_INFO = MavenInfo(
maven_coordinates = None,
maven_dependencies = depset(),
maven_dependencies = [],
)

_MAVEN_COORDINATES_PREFIX = "maven_coordinates="
Expand Down Expand Up @@ -114,7 +114,7 @@ def _collect_maven_info_impl(_target, ctx):
deps = depset([], transitive = [depset([d]) for d in _maven_coordinates(deps + exports + jars)])
filtered_deps = [
d
for d in deps
for d in deps.to_list()
if not (only_external_deps and (d.split(":")[0].startswith("com.daml") or
d.split(":")[0].startswith("com.digitalasset")))
]
Expand Down
4 changes: 2 additions & 2 deletions bazel_tools/scala-escape-jvmflags.patch
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ index f54a578..0d871ef 100644
.addKeyValuePair("java_start_class", javaStartClass)
.addKeyValuePair("classpath", classpath)
- .addJoinedValues("jvm_flags", " ", jvmFlags)
+ .addKeyValuePair("escape_jvmflags", "0")
+ .addKeyValuePair("escape_jvmflags", "1")
+ .addJoinedValues("jvm_flags", "\t", jvmFlags)
.build();

Path launcher = Paths.get(Runfiles.create().rlocation("bazel_tools/tools/launcher/launcher.exe"));
Path launcher = Paths.get(Runfiles.create().rlocation("bazel_tools/tools/launcher/launcher.exe"));
2 changes: 1 addition & 1 deletion bazel_tools/scala.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ def _scaladoc_jar_impl(ctx):
# which breaks scala macros

elif hasattr(p, "files"):
pluginPaths.extend([f for f in p.files if "-sources.jar" not in f.basename])
pluginPaths.extend([f for f in p.files.to_list() if "-sources.jar" not in f.basename])

transitive_deps = [dep[JavaInfo].transitive_deps for dep in ctx.attr.deps]
classpath = depset([], transitive = transitive_deps).to_list()
Expand Down
6 changes: 3 additions & 3 deletions daml-assistant/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
# SPDX-License-Identifier: Apache-2.0

load("//bazel_tools:haskell.bzl", "da_haskell_binary", "da_haskell_library", "da_haskell_repl", "da_haskell_test")
load("//bazel_tools:packaging/packaging.bzl", "package_app")
load("//bazel_tools/packaging:packaging.bzl", "package_app")
load("@os_info//:os_info.bzl", "is_windows")

# This library is intended to be used by applications called by the assistant,
# e.g., damlc, to get the names of the various environment variables set by the assistant.
da_haskell_library(
name = "daml-project-config",
srcs = native.glob(["daml-project-config/**/*.hs"]),
srcs = glob(["daml-project-config/**/*.hs"]),
hazel_deps = [
"base",
"directory",
Expand All @@ -28,7 +28,7 @@ da_haskell_library(

da_haskell_library(
name = "daml-lib",
srcs = native.glob(
srcs = glob(
["src/**/*.hs"],
exclude = [
"src/DAML/Assistant.hs",
Expand Down
2 changes: 1 addition & 1 deletion daml-assistant/daml-helper/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# SPDX-License-Identifier: Apache-2.0

load("//bazel_tools:haskell.bzl", "da_haskell_binary", "da_haskell_library", "da_haskell_test")
load("//bazel_tools:packaging/packaging.bzl", "package_app")
load("//bazel_tools/packaging:packaging.bzl", "package_app")
load("@os_info//:os_info.bzl", "is_windows")

da_haskell_library(
Expand Down
7 changes: 6 additions & 1 deletion daml-foundations/daml-tools/daml-extension/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

package(default_visibility = ["//visibility:public"])

load("@build_bazel_rules_typescript//:defs.bzl", "ts_library")
load("@npm_bazel_typescript//:index.bzl", "ts_library")
load("@build_bazel_rules_nodejs//:defs.bzl", "npm_package")
load("//bazel_tools:pkg.bzl", "pkg_tar")

Expand All @@ -15,6 +15,11 @@ ts_library(
srcs = ["src/extension.ts"],
node_modules = "@daml_extension_deps//:node_modules",
tsconfig = ":tsconfig.json",
deps = [
"@daml_extension_deps//@types",
"@daml_extension_deps//vscode",
"@daml_extension_deps//vscode-languageclient",
],
)

# With this rule we get access to extension.js, as
Expand Down
1 change: 1 addition & 0 deletions daml-foundations/daml-tools/daml-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@
"@types/which": "1.3.1"
},
"devDependencies": {
"@bazel/hide-bazel-files": "0.32.2",
"typescript": "3.3.3",
"@types/node": "6.0.42",
"vscode": "1.1.33"
Expand Down
Loading

0 comments on commit df7bff6

Please sign in to comment.