From 979de1592dc820bde86dfcf17165ffa2e8a70055 Mon Sep 17 00:00:00 2001 From: Judah Jacobson Date: Fri, 27 Jul 2018 01:16:45 -0700 Subject: [PATCH] Allow rules to override -O2 with their own compiler_flags. (#373) * Allow rules to override -O2 with their own compiler_flags. Currently, `-c opt` will turn on optimization for all Haskell rules with no way to disable it. Previously, it was possible to do so with `compiler_flags = ["-O0"]`, but that behavior was changed in #342: https://github.com/tweag/rules_haskell/pull/342/files#diff-33a8c46955e2a9917090b5258346aee2L247 Some Haskell packages take a *lot* of memory and a lot longer to compile with optimizations. So it's useful for us to be able to control this tradeoff. --- haskell/private/actions/compile.bzl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/haskell/private/actions/compile.bzl b/haskell/private/actions/compile.bzl index a8e2ed6e0..870f7cc97 100644 --- a/haskell/private/actions/compile.bzl +++ b/haskell/private/actions/compile.bzl @@ -275,12 +275,13 @@ def _compilation_defaults(hs, cc, java, dep_info, srcs, import_dir_map, extra_sr ghc_args += unit_id_args args = hs.actions.args() - args.add(ghc_args) - # Compilation mode and explicit user flags + # Compilation mode. Allow rule-supplied compiler flags to override it. if hs.mode == "opt": args.add("-O2") + args.add(ghc_args) + args.add(["-static"]) # NOTE We can't have profiling and dynamic code at the same time, see: