Switch to Hooks API instead of using cabal configure hack for lib/include dirs
This commit is contained in:
parent
718554cb2e
commit
ddb9c300cf
33
SetupHooks.hs
Normal file
33
SetupHooks.hs
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
{-# LANGUAGE DisambiguateRecordFields #-}
|
||||||
|
{-# LANGUAGE DuplicateRecordFields #-}
|
||||||
|
{-# LANGUAGE NoFieldSelectors #-}
|
||||||
|
|
||||||
|
module SetupHooks (setupHooks) where
|
||||||
|
|
||||||
|
import Distribution.Simple.SetupHooks
|
||||||
|
import Distribution.Utils.Path
|
||||||
|
import System.Directory
|
||||||
|
|
||||||
|
setupHooks :: SetupHooks
|
||||||
|
setupHooks =
|
||||||
|
noSetupHooks
|
||||||
|
{ configureHooks =
|
||||||
|
noConfigureHooks
|
||||||
|
{ preConfComponentHook = Just addRustLibDir
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
addRustLibDir :: PreConfComponentInputs -> IO PreConfComponentOutputs
|
||||||
|
addRustLibDir inputs = do
|
||||||
|
cwd <- getCurrentDirectory
|
||||||
|
pure
|
||||||
|
(noPreConfComponentOutputs inputs :: PreConfComponentOutputs)
|
||||||
|
{ componentDiff =
|
||||||
|
buildInfoComponentDiff
|
||||||
|
(componentName (component inputs))
|
||||||
|
emptyBuildInfo
|
||||||
|
{ extraLibDirs =
|
||||||
|
[ makeSymbolicPath $ cwd </> "rust" </> "target" </> "debug"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
11
garnet.cabal
11
garnet.cabal
@ -1,4 +1,4 @@
|
|||||||
cabal-version: 3.0
|
cabal-version: 3.14
|
||||||
name: garnet
|
name: garnet
|
||||||
version: 0.1.0.0
|
version: 0.1.0.0
|
||||||
license: BSD-3-Clause
|
license: BSD-3-Clause
|
||||||
@ -6,6 +6,14 @@ author: Patrick Aldis
|
|||||||
maintainer:
|
maintainer:
|
||||||
george.thomas@obsidian.systems
|
george.thomas@obsidian.systems
|
||||||
patrick.aldis@obsidian.systems
|
patrick.aldis@obsidian.systems
|
||||||
|
build-type: Hooks
|
||||||
|
|
||||||
|
custom-setup
|
||||||
|
setup-depends:
|
||||||
|
base,
|
||||||
|
Cabal-hooks,
|
||||||
|
Cabal-syntax,
|
||||||
|
directory,
|
||||||
|
|
||||||
common common
|
common common
|
||||||
default-language: GHC2024
|
default-language: GHC2024
|
||||||
@ -40,6 +48,7 @@ library
|
|||||||
GarnetRs.Raw
|
GarnetRs.Raw
|
||||||
GarnetRs.Wrapped
|
GarnetRs.Wrapped
|
||||||
hs-source-dirs: lib
|
hs-source-dirs: lib
|
||||||
|
include-dirs: rust/target/debug
|
||||||
extra-bundled-libraries: garnet_rs
|
extra-bundled-libraries: garnet_rs
|
||||||
build-depends:
|
build-depends:
|
||||||
base,
|
base,
|
||||||
|
|||||||
@ -9,12 +9,11 @@ set -euo pipefail
|
|||||||
# 1. cargo build - build the Rust static library
|
# 1. cargo build - build the Rust static library
|
||||||
# 2. cbindgen - generate a C header from the Rust source
|
# 2. cbindgen - generate a C header from the Rust source
|
||||||
# 3. awk - patch the header for hs-bindgen compatibility
|
# 3. awk - patch the header for hs-bindgen compatibility
|
||||||
# 4. cabal configure - point Cabal at the Rust build artifacts
|
|
||||||
#
|
#
|
||||||
# System include paths (needed by libclang on NixOS) are detected
|
# System include paths (needed by libclang on NixOS) are detected
|
||||||
# automatically at TH compile time by GarnetRs.Raw — no env vars needed.
|
# automatically at TH compile time by GarnetRs.Raw — no env vars needed.
|
||||||
#
|
#
|
||||||
# Prerequisites: run inside the Nix dev shell (provides gcc, cabal, cbindgen).
|
# Prerequisites: run inside the Nix dev shell (provides gcc, cbindgen).
|
||||||
|
|
||||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||||
RUST_DIR="$SCRIPT_DIR/rust"
|
RUST_DIR="$SCRIPT_DIR/rust"
|
||||||
@ -58,15 +57,5 @@ awk '
|
|||||||
|
|
||||||
echo " Patched header at $HEADER"
|
echo " Patched header at $HEADER"
|
||||||
|
|
||||||
# --- Step 4: Configure Cabal ---
|
|
||||||
#
|
|
||||||
# Point Cabal at the Rust static library and C header. This writes
|
|
||||||
# cabal.project.local (gitignored) with absolute paths derived from
|
|
||||||
# the current working directory, avoiding hardcoded paths in cabal.project.
|
|
||||||
echo "=== Configuring Cabal ==="
|
|
||||||
cabal configure \
|
|
||||||
--extra-lib-dirs="$RUST_DIR/target/debug" \
|
|
||||||
--extra-include-dirs="$RUST_DIR/target/debug"
|
|
||||||
|
|
||||||
echo "=== Done ==="
|
echo "=== Done ==="
|
||||||
echo "Run 'cabal run' to test."
|
echo "Run 'cabal run' to test."
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user