diff --git a/.bazelrc b/.bazelrc index 31a414241..cdaf74744 100644 --- a/.bazelrc +++ b/.bazelrc @@ -8,7 +8,7 @@ build --disk_cache=.bazel-cache/bazel-disk build --repository_cache=tmp/bazel-repo build --color=yes build --jobs=8 - +common --compilation_mode=fastbuild # test environment does not propagate locales by default # some tests reads files written in UTF8, we need to propagate the correct diff --git a/BUILD.bazel b/BUILD.bazel index 1ff84ef69..4668b90b9 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -34,6 +34,21 @@ haskell_toolchain_library(name = "template-haskell") haskell_toolchain_library(name = "transformers") +config_setting( + name = "release", + values = {"compilation_mode": "opt"}, +) + +config_setting( + name = "development", + values = {"compilation_mode": "fastbuild"}, +) + +config_setting( + name = "debug", + values = {"compilation_mode": "dbg"}, +) + haskell_repl( name = "hie-bios", collect_data = False, diff --git a/build/common.bzl b/build/common.bzl index c1ee8517a..46c0833b3 100644 --- a/build/common.bzl +++ b/build/common.bzl @@ -7,8 +7,10 @@ load( ) load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") -STANDARD_GHC_WARNINGS = [ - "-O0", +DEVELOPMENT_GHC_FLAGS = ["-O0"] +RELEASE_GHC_FLAGS = ["-O1"] + +GHC_FLAGS = [ "-v1", "-j8", "-fdiagnostics-color=always", @@ -25,7 +27,13 @@ STANDARD_GHC_WARNINGS = [ "-Wno-all-missed-specialisations", "-Wno-star-is-type", "-Wno-missing-deriving-strategies", -] +] + select( + { + "//:release": RELEASE_GHC_FLAGS, + "//:development": DEVELOPMENT_GHC_FLAGS, + "//:debug": DEVELOPMENT_GHC_FLAGS, + }, +) STANDARD_EXECUTABLE_FLAGS = [ "-threaded", @@ -58,10 +66,10 @@ def semantic_language_library(language, name, srcs, ts_package = "", nodetypes = # We can't use Template Haskell to find out the location of the # node-types.json files, but we can pass it in as a preprocessor # directive. - compiler_flags = STANDARD_GHC_WARNINGS + [ + compiler_flags = GHC_FLAGS + [ '-DNODE_TYPES_PATH="../../../../$(rootpath {})"'.format(nodetypes), ], - repl_ghci_args = STANDARD_GHC_WARNINGS + [ + repl_ghci_args = GHC_FLAGS + [ '-DNODE_TYPES_PATH="../../../../$(rootpath {})"'.format(nodetypes), ], srcs = srcs, diff --git a/docs/build.md b/docs/build.md index 2398cf2e1..7bed3f51b 100644 --- a/docs/build.md +++ b/docs/build.md @@ -20,8 +20,9 @@ The first time you run `bazel build`, it'll take some time, as Bazel will compil | Build `TARGET` library | `cabal build TARGET:lib` | `bazel build //TARGET` | | Build semantic executable | `cabal build semantic:exe:semantic` | `bazel build //semantic:exe` | | Build/run executable | `cabal run semantic -- ARGS` | `bazel run //semantic:exe -- ARGS` | -| Load REPL component | `script/ghci` and `:load` | `bazel build //TARGET@repl` | +| Load REPL component | `script/ghci` and `:load` | `bazel build //TARGET@repl` | | Run tests | `cabal test all` | `bazel test //...` | +| Build with optimizations | `cabal build --flags="+release"` | `bazel build -copt //...` | ## Adding a new dependency @@ -53,7 +54,7 @@ The default `.bazelrc` file imports a `.bazelrc.local` file if it's present; use ## Shared variables -* `STANDARD_GHC_WARNINGS`: the standard set of Cabal flags that all targets should use. +* `GHC_FLAGS`: the standard set of Cabal flags that all targets should use. * `STANDARD_EXECUTABLE_FLAGS`: ditto, but with executable-specific flags. ## Custom rules diff --git a/semantic-analysis/BUILD.bazel b/semantic-analysis/BUILD.bazel index b97003be6..5c1c730ec 100644 --- a/semantic-analysis/BUILD.bazel +++ b/semantic-analysis/BUILD.bazel @@ -14,13 +14,13 @@ load( ) load( "//:build/common.bzl", - "STANDARD_GHC_WARNINGS", + "GHC_FLAGS", ) haskell_library( name = "semantic-analysis", srcs = glob(["src/**/*.hs"]), - compiler_flags = STANDARD_GHC_WARNINGS + ["-XOverloadedStrings"], + compiler_flags = GHC_FLAGS + ["-XOverloadedStrings"], deps = [ "//:base", "//:containers", diff --git a/semantic-ast/BUILD.bazel b/semantic-ast/BUILD.bazel index 07db912d6..135bcf1c0 100644 --- a/semantic-ast/BUILD.bazel +++ b/semantic-ast/BUILD.bazel @@ -14,13 +14,13 @@ load( ) load( "//:build/common.bzl", - "STANDARD_GHC_WARNINGS", + "GHC_FLAGS", ) haskell_library( name = "semantic-ast", srcs = glob(["src/**/*.hs"]), - compiler_flags = STANDARD_GHC_WARNINGS + ["-XOverloadedStrings"], + compiler_flags = GHC_FLAGS + ["-XOverloadedStrings"], deps = [ "//:base", "//:bytestring", diff --git a/semantic-codeql/BUILD.bazel b/semantic-codeql/BUILD.bazel index 6e6f284ae..54631fb81 100644 --- a/semantic-codeql/BUILD.bazel +++ b/semantic-codeql/BUILD.bazel @@ -14,5 +14,6 @@ semantic_language_library( semantic_language_parsing_test( language = "codeql", - project = "ql", + semantic_package = "ql", + ts_package = "ql", ) diff --git a/semantic-core/BUILD.bazel b/semantic-core/BUILD.bazel index 8bb4b1757..9cf24f642 100644 --- a/semantic-core/BUILD.bazel +++ b/semantic-core/BUILD.bazel @@ -14,14 +14,14 @@ load( ) load( "//:build/common.bzl", + "GHC_FLAGS", "STANDARD_EXECUTABLE_FLAGS", - "STANDARD_GHC_WARNINGS", ) haskell_library( name = "semantic-core", srcs = glob(["src/**/*.hs"]), - compiler_flags = STANDARD_GHC_WARNINGS, + compiler_flags = GHC_FLAGS, deps = [ "//:base", "//:text", @@ -45,7 +45,7 @@ haskell_test( "test/*.hs", "test/Source/Test.hs", ]), - compiler_flags = STANDARD_GHC_WARNINGS + STANDARD_EXECUTABLE_FLAGS, + compiler_flags = GHC_FLAGS + STANDARD_EXECUTABLE_FLAGS, deps = [ "//:base", "//:text", diff --git a/semantic-parse/BUILD.bazel b/semantic-parse/BUILD.bazel index 4698e9fb8..171a5890a 100644 --- a/semantic-parse/BUILD.bazel +++ b/semantic-parse/BUILD.bazel @@ -8,7 +8,7 @@ load( ) load( "//:build/common.bzl", - "STANDARD_GHC_WARNINGS", + "GHC_FLAGS", ) # Doesn't build right now. @@ -16,7 +16,7 @@ load( haskell_binary( name = "exe", srcs = ["app/Main.hs"], - compiler_flags = STANDARD_GHC_WARNINGS, + compiler_flags = GHC_FLAGS, deps = [ "//:base", "//:bytestring", diff --git a/semantic-scope-graph/BUILD.bazel b/semantic-scope-graph/BUILD.bazel index 66ef5c5d3..c9c18de70 100644 --- a/semantic-scope-graph/BUILD.bazel +++ b/semantic-scope-graph/BUILD.bazel @@ -14,13 +14,13 @@ load( ) load( "//:build/common.bzl", - "STANDARD_GHC_WARNINGS", + "GHC_FLAGS", ) haskell_library( name = "semantic-scope-graph", srcs = glob(["src/**/*.hs"]), - compiler_flags = STANDARD_GHC_WARNINGS + ["-XOverloadedStrings"], + compiler_flags = GHC_FLAGS + ["-XOverloadedStrings"], deps = [ "//:base", "//:containers", diff --git a/semantic-source/BUILD.bazel b/semantic-source/BUILD.bazel index 2c366fcc4..a4d108656 100644 --- a/semantic-source/BUILD.bazel +++ b/semantic-source/BUILD.bazel @@ -14,14 +14,14 @@ load( ) load( "//:build/common.bzl", + "GHC_FLAGS", "STANDARD_EXECUTABLE_FLAGS", - "STANDARD_GHC_WARNINGS", ) haskell_library( name = "semantic-source", srcs = glob(["src/**/*.hs"]), - compiler_flags = STANDARD_GHC_WARNINGS + ["-XOverloadedStrings"], + compiler_flags = GHC_FLAGS + ["-XOverloadedStrings"], deps = [ "//:base", "//:bytestring", @@ -44,7 +44,7 @@ haskell_test( "test/Source/Test.hs", "test/Test.hs", ], - compiler_flags = STANDARD_GHC_WARNINGS + STANDARD_EXECUTABLE_FLAGS, + compiler_flags = GHC_FLAGS + STANDARD_EXECUTABLE_FLAGS, deps = [ ":semantic-source", "//:base", diff --git a/semantic-tags/BUILD.bazel b/semantic-tags/BUILD.bazel index 17b4c4a85..003f6527b 100644 --- a/semantic-tags/BUILD.bazel +++ b/semantic-tags/BUILD.bazel @@ -14,13 +14,13 @@ load( ) load( "//:build/common.bzl", - "STANDARD_GHC_WARNINGS", + "GHC_FLAGS", ) haskell_library( name = "semantic-tags", srcs = glob(["src/**/*.hs"]), - compiler_flags = STANDARD_GHC_WARNINGS, + compiler_flags = GHC_FLAGS, deps = [ "//:base", "//:text", diff --git a/semantic/BUILD.bazel b/semantic/BUILD.bazel index f2233da76..3fffa0cb6 100644 --- a/semantic/BUILD.bazel +++ b/semantic/BUILD.bazel @@ -16,8 +16,8 @@ load( ) load( "//:build/common.bzl", + "GHC_FLAGS", "STANDARD_EXECUTABLE_FLAGS", - "STANDARD_GHC_WARNINGS", ) load( "//:build/example_repos.bzl", @@ -55,7 +55,7 @@ semantic_common_dependencies = [ haskell_library( name = "semantic", srcs = glob(["src/**/*.hs"]), - compiler_flags = STANDARD_GHC_WARNINGS + ["-XStrictData"], + compiler_flags = GHC_FLAGS + ["-XStrictData"], version = "0.11.0.0", deps = semantic_common_dependencies + [ "//:base", @@ -110,7 +110,7 @@ haskell_library( haskell_binary( name = "exe", srcs = glob(["app/**/*.hs"]), - compiler_flags = STANDARD_GHC_WARNINGS + STANDARD_EXECUTABLE_FLAGS + ["-XStrictData"], + compiler_flags = GHC_FLAGS + STANDARD_EXECUTABLE_FLAGS + ["-XStrictData"], deps = [ ":semantic", "//:base", @@ -142,7 +142,7 @@ haskell_test( "test/System/Path/Fixture.hs", ], ), - compiler_flags = STANDARD_GHC_WARNINGS + STANDARD_EXECUTABLE_FLAGS + [ + compiler_flags = GHC_FLAGS + STANDARD_EXECUTABLE_FLAGS + [ "-XStrictData", ], data = glob(include = [ @@ -186,7 +186,7 @@ haskell_test( srcs = [ "test/Examples.hs", ], - compiler_flags = STANDARD_GHC_WARNINGS + STANDARD_EXECUTABLE_FLAGS + [ + compiler_flags = GHC_FLAGS + STANDARD_EXECUTABLE_FLAGS + [ "-XStrictData", ], data = glob(include = [