Skip to content

Add -plugin-package-db for cross-compilation plugin support#172

Open
angerman wants to merge 3 commits intostable-ghc-9.14from
feat/plugin-package-db
Open

Add -plugin-package-db for cross-compilation plugin support#172
angerman wants to merge 3 commits intostable-ghc-9.14from
feat/plugin-package-db

Conversation

@angerman
Copy link
Copy Markdown

@angerman angerman commented Mar 5, 2026

Summary

  • Adds -plugin-package-db and -clear-plugin-package-dbs flags so GHC can point at host-side package databases for plugin resolution during cross-compilation
  • When -plugin-package-db is specified, builds a separate UnitState from host package DBs using hostPlatformArchOS, so plugins load host libraries while TH/bytecode continues using the target UnitState via the external interpreter
  • Replaces checkExternalInterpreter (which errored on -fexternal-interpreter + plugins) with withPluginInterp, which creates a local InternalInterp for plugin loading alongside the external interpreter (#14335)

Architecture

No -plugin-package-db (native, unchanged):
  plugins → InternalInterp + existing UnitState

With -plugin-package-db (cross-compilation):
  plugins → InternalInterp + host plugin UnitState (from host DBs)
  TH/GHCi → ExternalInterp + target UnitState (unchanged)

Files changed

File Change
compiler/GHC/Driver/DynFlags.hs Add pluginPackageDBFlags field + recompilation check
compiler/GHC/Driver/Session.hs Parse -plugin-package-db, -clear-plugin-package-dbs
compiler/GHC/Unit/State.hs Add initPluginUnitConfig (host platform, plugin DBs)
compiler/GHC/Driver/Env.hs Add hscSetCurrentUnitState helper
compiler/GHC/Runtime/Loader.hs Extend withPluginInterp to swap in host UnitState

Test plan

  • Native compilation + plugins: unchanged behavior (no -plugin-package-db specified)
  • -fexternal-interpreter + plugins (native): plugins load via InternalInterp, TH via iserv — no regression
  • Cross-compilation + -plugin-package-db /path/to/host/db: plugins resolve from host DB, load host libraries
  • No plugins: no behavior change
  • -fplugin-library: still works (independent path)

angerman added 3 commits March 6, 2026 10:09
When cross-compiling (host != target), plugins are built for the host
platform but GHC's UnitState contains target packages. Loading target
libraries into GHC's host process fails.

This adds a -plugin-package-db flag that points GHC at host-side
package databases. When specified, a separate UnitState is built from
these databases for plugin loading, while TH/bytecode continues to
use the target UnitState via the external interpreter.

Architecture:
  No -plugin-package-db:
    plugins use InternalInterp + existing target UnitState (unchanged)
  With -plugin-package-db:
    plugins use InternalInterp + host plugin UnitState (from host DBs)
    TH/GHCi uses ExternalInterp + target UnitState (unchanged)

Changes:
- DynFlags: add pluginPackageDBFlags field
- Session: parse -plugin-package-db and -clear-plugin-package-dbs flags
- Unit/State: add initPluginUnitConfig using hostPlatformArchOS
- Driver/Env: add hscSetCurrentUnitState helper
- Runtime/Loader: extend withPluginInterp to swap UnitState when
  plugin DBs are configured; replace checkExternalInterpreter with
  withPluginInterp (creates local InternalInterp for plugin loading
  alongside ExternalInterp for TH, see #14335)
T14335 previously tested that plugins + -fexternal-interpreter
produced an error. With the new dual-interpreter architecture,
plugins load via InternalInterp while TH uses the external
interpreter, so this combination now succeeds.

Change compile_fail → compile and remove the .stderr file.
The plugin now runs successfully with -fexternal-interpreter,
producing its normal output (plugin passes queried, options, pass run).
Add the expected stderr to match.
@angerman angerman force-pushed the feat/plugin-package-db branch from f838dbf to e1ab30b Compare March 6, 2026 01:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant