Skip to content

Commit

Permalink
Default to -c opt in Bazel (digital-asset#2592)
Browse files Browse the repository at this point in the history
This makes sure that C dependencies like gRPC or zlib get compiled
with optimizations. I patched rules_haskell to use -O instead of -O2
since the latter slows down compilation while not making things
faster (according to my measurements).
  • Loading branch information
cocreature authored Aug 19, 2019
1 parent 47238a5 commit 1192338
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,9 @@ build:darwin --protocopt=--include_source_info
# using ComSpec environment variable. By default it's not passed from Bazel client environment.
test:windows --test_env=ComSpec

# We default to -c opt. We compile Haskell with -O1 anyway since otherwise
# it is unusably slow and the C deps change rarely so there is little reason
# to not compile them with optimizations.
build -c opt

try-import %workspace%/.bazelrc.local
2 changes: 2 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,8 @@ exports_files(glob(["lib/**/*"]))
) if not is_windows else None

common_ghc_flags = [
# We default to -c opt but we also want -O1 in -c dbg builds
# since we use them for profiling.
"-O1",
"-hide-package=ghc-boot-th",
"-hide-package=ghc-boot",
Expand Down
13 changes: 13 additions & 0 deletions bazel_tools/haskell-opt.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/haskell/private/actions/compile.bzl b/haskell/private/actions/compile.bzl
index ac8725f5..3f6e4b40 100644
--- a/haskell/private/actions/compile.bzl
+++ b/haskell/private/actions/compile.bzl
@@ -250,7 +250,7 @@ def _compilation_defaults(hs, cc, java, dep_info, plugin_dep_info, cc_info, srcs

# Compilation mode. Allow rule-supplied compiler flags to override it.
if hs.mode == "opt":
- args.add("-O2")
+ args.add("-O")

args.add("-static")
if with_profiling:
1 change: 1 addition & 0 deletions deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def daml_deps():
"@com_github_digital_asset_daml//bazel_tools:haskell_public_ghci_repl_wrapper.patch",
"@com_github_digital_asset_daml//bazel_tools:haskell-windows-library-dirs.patch",
"@com_github_digital_asset_daml//bazel_tools:haskell-no-isystem.patch",
"@com_github_digital_asset_daml//bazel_tools:haskell-opt.patch",
],
patch_args = ["-p1"],
sha256 = rules_haskell_sha256,
Expand Down

0 comments on commit 1192338

Please sign in to comment.