xiaohongshu
xiaohongshu
debug-haskell-bazel-targets
Diagnose and fix common Haskell Bazel build errors, especially dependency visibility issues
Full skill instructions
This skill helps diagnose and fix common Haskell Bazel build errors, particularly dependency visibility and configuration issues.
ERROR: in _haskell_test rule //path/to:target: target '@@rules_haskell~~stack_snapshot~stackage//:base' is not visible from target '//path/to:target'
Core Haskell packages (base, bytestring, containers, directory, filepath, text, time, etc.) should NOT be imported from @stackage//. They are part of the GHC distribution and must be referenced directly.
WRONG:
haskell_test(
name = "unit-tests",
srcs = glob(["test/**/*.hs"]),
deps = [
":rpg-ruleset-core",
"@stackage//:QuickCheck",
"@stackage//:base", # L WRONG
"@stackage//:hspec",
"@stackage//:text", # L WRONG
],
)
CORRECT:
haskell_test(
name = "unit-tests",
srcs = glob(["test/**/*.hs"]),
deps = [
":rpg-ruleset-core",
"//:base", # CORRECT
"//:text", # CORRECT
"@stackage//:QuickCheck", # Third-party packages use @stackage//
"@stackage//:hspec",
],
)
//:package-name)//:base//:bytestring//:containers//:directory//:filepath//:text//:time//:array//:deepseq//:process//:mtl//:transformers@stackage//:package-name)@stackage//:aeson@stackage//:yaml@stackage//:cmark@stackage//:QuickCheck@stackage//:hspec@stackage//:http-conduit@stackage//:optparse-applicativeWhen encountering build errors:
Identify the error type
//: vs @stackage//)For visibility errors:
# Check which dependencies are causing issues
grep -r "@stackage//:base" haskell/
grep -r "@stackage//:text" haskell/
grep -r "@stackage//:containers" haskell/
Fix all BUILD.bazel files:
@stackage//:base � //:base@stackage//:text � //:text@stackage//:containers � //:containers@stackage// for third-party packagesVerify consistency across library and test targets:
haskell_library deps should match haskell_test deps for core packages//: prefix for GHC-bundled packagesRebuild:
bazel clean
bazel build //...
bazel test //...
# Template for Haskell library/binary/test
haskell_library(
name = "my-lib",
srcs = glob(["src/**/*.hs"]),
src_strip_prefix = "src",
visibility = ["//visibility:public"],
deps = [
# Core GHC packages (no @stackage)
"//:base",
"//:bytestring",
"//:containers",
"//:directory",
"//:filepath",
"//:text",
"//:time",
# Third-party packages (with @stackage)
"@stackage//:aeson",
"@stackage//:yaml",
"@stackage//:cmark",
],
)
haskell_test(
name = "unit-tests",
srcs = glob(["test/**/*.hs"]),
src_strip_prefix = "test",
deps = [
":my-lib",
# Core GHC packages
"//:base",
"//:text",
# Test frameworks (third-party)
"@stackage//:QuickCheck",
"@stackage//:hspec",
],
)
ERROR: No source file defining the main module 'Main'.
You may need to set the 'main_file' attribute or the 'module_name' attribute in a 'haskell_module' rule.
The haskell_test rule expects actual Haskell test files (*.hs) but the test directory may only contain fixtures or be empty.
Remove the test target if no tests exist yet:
# Remove or comment out until tests are written
# haskell_test(
# name = "unit-tests",
# srcs = glob(["test/**/*.hs"]),
# ...
# )
Or create a minimal test file (test/Main.hs):
module Main where
main :: IO ()
main = putStrLn "Tests not implemented yet"
Build fails or can't find source files when using custom dependencies from non_module_deps.bzl
The strip_prefix in http_archive changes the directory structure, but the glob pattern in build_file_content doesn't match the post-strip structure.
When using strip_prefix:
http_archive(
name = "libyaml",
urls = ["https://hackage.haskell.org/package/libyaml-0.1.4/libyaml-0.1.4.tar.gz"],
strip_prefix = "libyaml-0.1.4", # ← Directory is stripped
build_file_content = """
haskell_cabal_library(
name = "libyaml",
srcs = glob(["**/*"]), # ✓ Use glob without directory prefix
...
)
"""
)
Without strip_prefix:
http_archive(
name = "yaml",
urls = ["https://hackage.haskell.org/package/yaml-0.11.11.2/yaml-0.11.11.2.tar.gz"],
# No strip_prefix ← Directory preserved
build_file_content = """
haskell_cabal_library(
name = "yaml",
srcs = glob(["yaml-0.11.11.2/**/*"]), # ✓ Include directory in glob
...
)
"""
)
Debugging tip: Check the actual directory structure in the external repository:
ls -la ~/.bazel/external/_main~non_module_deps~<package-name>/
@@rules_haskell~~stack_snapshot~stackage - this is Bazel's canonical repository name--verbose_failures flag for detailed error informationbazel clean if caching causes issuesstrip_prefix is appliedInvoke this skill when:
haskell_library, haskell_binary, or haskell_test targetsxiaohongshu
technical spec
product ux expert
database patterns
Conduct multi-agent task orchestration and workflow coordination.
Initialize project with Conductor artifacts (product definition,
Expert in web animations, transitions, and motion design using Framer Motion and CSS
Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...
PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.
Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...
Display project status, active tracks, and next actions
Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.
Generate, edit, and beat-sync AI video with leading models in one workspace.
The world's fastest calendar for remote work
Transform Your Design with AI Designer by ImgCreator.ai
Revolutionizing Video Production with AI-Powered Creativity
Extend an image past the frame and let AI fill the new aspect ratio.
Discover your celebrity doppelgänger with StarByFace!
ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.
Opus.ai: Revolutionize Your Web Experience