"output ... was not created" when building base-noprelude
I am attempting to use an alternative prelude, but am getting the following error when building base-noprelude, against a stack_snapshot of lts-14.0:
ERROR: /private/var/tmp/_bazel_josephprice/b90ee53fffa6993c9bf551d9de451812/external/stackage/BUILD.bazel:93:1: output 'external/stackage/base-noprelude-4.12.0.0/_install/base-noprelude-4.12.0.0_haddock/base-noprelude.haddock' was not created
ERROR: /private/var/tmp/_bazel_josephprice/b90ee53fffa6993c9bf551d9de451812/external/stackage/BUILD.bazel:93:1: output 'external/stackage/base-noprelude-4.12.0.0/_install/lib/libHSbase-noprelude-4.12.0.0-ghc8.6.5.dylib' was not created```
**Environment**
- OS name + version: OSX 10.15.3
- Bazel version: 2.0.0
- Version of the rules: cf6beb4e3748dce6dc401a95ab8cacb803c5d944
Thanks for raising this issue.
With Bazel all inputs and outputs have to be predeclared. In case of haskell_cabal_library, which stack_snapshot uses under the hood, we predeclare the library and optionally haddock outputs. If they are not created, then Bazel will fail with the error that you observe.
Right now stack_snapshot works around known empty packages, e.g. bytestring-builder, by defining an empty haskell_library target instead. However, this will probably not work for base-noprelude. While it is an empty package in the sense that it doesn't create a library, it does create a non-empty package configuration that forwards base modules. At this point this is not supported by haskell_cabal_library.
However, haskell_library supports module reexports. So, I think the following approach should allow you to achieve the effect of base-noprelude with rules_haskell as of now.
- Define a
haskell_librarythat mimicsbase-noprelude. say//third_party/base-noprelude:base-no-prelude, like so:# Copy the Cabal file for base-noprelude, `stack_snapshot` assumes its presence. exports_files(["base-noprelude.cabal"]) haskell_toolchain_library(name = "base") haskell_library( name = "base-noprelude", deps = [":base"], reexported_modules = { # module list taken from https://hackage.haskell.org/package/base-noprelude-4.13.0.0/base-noprelude.cabal ":base": "Control.Applicative, Control.Arrow, Control.Category, ...", }, ) - Insert this
haskell_libraryintostack_snapshotas a vendored package.stack_snapshot( ... venodred_packages = {"base-noprelude": "//third_party/base-nodeprelude"}, )
I haven't tested this, let me know if you encounter issues with this approach.
I hope this helps.
Thank you for the alternative. For now, I'm passing -XNoImplicitPrelude to haskell_library's compiler_flags. This works for now, but I can imagine wanting to apply it across larger parts of a project. A macro would work there, and maybe it's also available as a flag to the toolchain? Do you see any advantages to using the base-no-prelude package versus using the compiler flag?
A macro would work there, and maybe it's also available as a flag to the toolchain?
A macro seems like the best solution to define common flags. It's common for Bazel projects to have macro wrappers around commonly used rules. In principle you could add it to the compiler_flags of the toolchain. However, that would apply to all Haskell targets, including those defined outside your workspace (e.g. the runfiles library in rules_haskell). Those would likely fail with -XNoImplicitPrelude.
Do you see any advantages to using the base-no-prelude package versus using the compiler flag?
I haven't used base-no-prelude so I can't speak from experience. My understanding is that it is a convenience to avoid the need for always setting -XNoImplicitPrelude. Using a macro wrapper achieves the same goal, to my understanding.
Thank you for the detailed explanation! I'll go with the compiler flag for now.
fwiw I just ran into this trying to use a Stackage snapshot. Some dependency (not sure which) wants @stackage//:base-noprelude and the build crashes out.
ERROR: /home/andrew/.cache/bazel/_bazel_andrew
/05ee94f881dbdb5d5ef28864733fb7a1/external/stackage
/BUILD.bazel:284:22: output 'external/stackage/base-noprelude-4.13.0.0
/_install/lib/libHSbase-noprelude-4.13.0.0.a' was not created
this isn't from my code, just a transitive dependency, so I can't go and do -XNoImplicitPrelude on it. Which ever it was, it's ultimately a dependency of pandoc. If you wish to reproduce this problem try building that using Bazel.
This has kind of brought using rules_haskell to an abrupt halt, but we'll keep trying.
I just hit a similar issue while trying to upgrade to ghc8.4.4 and pandoc. I've tried the suggestion but even when adding the fake base-noprelude as a vendored dependency I still get a
Setup.hs: Encountered missing or private dependencies:
base-noprelude >=4.9 && <5
I am considering pinning to a pandoc version prior to https://github.com/jgm/pandoc/pull/6187/files.
the use of base-noprelude in pandoc was reverted afterwwards so instead you can also use a more recent one.