Skip to content
debug-haskell-bazel-targets logo

Debug Haskell Bazel Targets

debug-haskell-bazel-targets

Diagnose and fix common Haskell Bazel build errors, especially dependency visibility issues

SKILL.md

Full skill instructions

Debug Haskell Bazel Targets

This skill helps diagnose and fix common Haskell Bazel build errors, particularly dependency visibility and configuration issues.

Common Error Pattern: Dependency Visibility

Symptom

ERROR: in _haskell_test rule //path/​to:target: target '@@rules_haskell~~stack_snapshot~stackage//:base' is not visible from target '//path/​to:target'

Root Cause

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.

Solution Pattern

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",
    ],
)

Core vs Third-Party Dependencies

Core GHC Packages (use //:package-name)

  • //:base
  • //:bytestring
  • //:containers
  • //:directory
  • //:filepath
  • //:text
  • //:time
  • //:array
  • //:deepseq
  • //:process
  • //:mtl
  • //:transformers

Third-Party Packages (use @stackage//:package-name)

  • @stackage//:aeson
  • @stackage//:yaml
  • @stackage//:cmark
  • @stackage//:QuickCheck
  • @stackage//:hspec
  • @stackage//:http-conduit
  • @stackage//:optparse-applicative
  • Any package not bundled with GHC

Debugging Workflow

When encountering build errors:

  1. Identify the error type

    • Visibility errors � Check dependency prefixes (//: vs @stackage//)
    • Missing dependencies � Check if package is in MODULE.bazel
    • Compilation errors � Check Haskell syntax and imports
  2. For visibility errors:

    # Check which dependencies are causing issues
    grep -r "@stackage//:base" haskell/
    grep -r "@stackage//:text" haskell/
    grep -r "@stackage//:containers" haskell/
    
  3. Fix all BUILD.bazel files:

    • Replace @stackage//:base � //:base
    • Replace @stackage//:text � //:text
    • Replace @stackage//:containers � //:containers
    • Keep @stackage// for third-party packages
  4. Verify consistency across library and test targets:

    • haskell_library deps should match haskell_test deps for core packages
    • Both should use //: prefix for GHC-bundled packages
  5. Rebuild:

    bazel clean
    bazel build //...
    bazel test //...
    

Quick Reference

# 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",
    ],
)

Common Error: Missing Test Files

Symptom

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.

Root Cause

The haskell_test rule expects actual Haskell test files (*.hs) but the test directory may only contain fixtures or be empty.

Solution

  1. 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"]),
    #     ...
    # )
    
  2. Or create a minimal test file (test/​Main.hs):

    module Main where
    main :: IO ()
    main = putStrLn "Tests not implemented yet"
    

Common Error: Custom Dependency Glob Pattern Mismatch

Symptom

Build fails or can't find source files when using custom dependencies from non_module_deps.bzl

Root Cause

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.

Solution Pattern

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>/

Additional Notes

  • The error message mentions @@rules_haskell~~stack_snapshot~stackage - this is Bazel's canonical repository name
  • GHCi warnings about missing binary are informational and don't affect builds
  • Use --verbose_failures flag for detailed error information
  • After fixing deps, run bazel clean if caching causes issues
  • For custom dependencies, verify glob patterns match the directory structure after strip_prefix is applied

When to Use This Skill

Invoke this skill when:

  • Encountering "not visible from target" errors with Haskell dependencies
  • Setting up new haskell_library, haskell_binary, or haskell_test targets
  • Migrating existing Haskell code to Bazel
  • Debugging BUILD.bazel dependency configuration

More skills from majiayu000

xiaohongshu logo
majiayu000/claude-arsenal

xiaohongshu

xiaohongshu

286 148
View
agent-task-conductor logo
majiayu000/claude-skill-registry

agent-task-conductor

Conduct multi-agent task orchestration and workflow coordination.

663 1
View
conductor-setup logo
majiayu000/claude-skill-registry

conductor-setup

Initialize project with Conductor artifacts (product definition,

663 1
View
animation-designer logo
majiayu000/claude-skill-registry

animation-designer

Expert in web animations, transitions, and motion design using Framer Motion and CSS

663 1
View
diagramming logo
majiayu000/claude-skill-registry

diagramming

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...

663 1
View
h3-pg logo
majiayu000/claude-skill-registry-data

h3-pg

PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.

23 1
View
conductor-development logo
majiayu000/claude-skill-registry

conductor-development

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...

663 1
View
conductor-status logo
majiayu000/claude-skill-registry

conductor-status

Display project status, active tracks, and next actions

663 1
View
dockerization logo
majiayu000/claude-skill-registry

dockerization

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.

663 1
View

Popular AI tools

Kaiber logo
Video

Kaiber

Generate, edit, and beat-sync AI video with leading models in one workspace.

Paid
View
Vimcal logo
Productivity

Vimcal

The world's fastest calendar for remote work

Free
View

Transform Your Design with AI Designer by ImgCreator.ai

Freemium
View
Akool AI logo
Content & writing

Akool AI

Revolutionizing Video Production with AI-Powered Creativity

Paid
View

Extend an image past the frame and let AI fill the new aspect ratio.

Freemium
View
StarByFace logo
Security

StarByFace

Discover your celebrity doppelgänger with StarByFace!

Free
View
C

ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.

Freemium
View
Opus Clip logo
Coding & apps

Opus Clip

Opus.ai: Revolutionize Your Web Experience

Free
View