Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions cabal-install/src/Distribution/Client/ProjectPlanning.hs
Original file line number Diff line number Diff line change
Expand Up @@ -251,11 +251,6 @@ sanityCheckElaboratedConfiguredPackage
ElabPackage pkg -> sanityCheckElaboratedPackage elab pkg
ElabComponent comp -> sanityCheckElaboratedComponent elab comp
)
-- The assertion below fails occasionally for unknown reason
-- so it was muted until we figure it out, otherwise it severely
-- hinders our ability to share and test development builds of cabal-install.
-- Tracking issue: https://github.com/haskell/cabal/issues/6006
--
-- either a package is being built inplace, or the
-- 'installedPackageId' we assigned is consistent with
-- the 'hashedInstalledPackageId' we would compute from
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

int abccd(int x) {
return (x * 32);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import A (bobble, isNeeded)

foreign import ccall razzle :: CInt -> CInt

foreign import ccall abccd :: CInt -> CInt

main = do
print bobble
print $ razzle 3
print $ isNeeded 77
print $ abccd 1
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module SetupHooks where
import Distribution.Compat.Binary
import Distribution.ModuleName
import Distribution.Simple.LocalBuildInfo
( interpretSymbolicPathLBI )
( interpretSymbolicPathLBI, mbWorkDirLBI )
import Distribution.Simple.SetupHooks
import Distribution.Simple.Utils
import Distribution.Types.LocalBuildInfo
Expand Down Expand Up @@ -65,7 +65,8 @@ pcc (PreConfComponentInputs _lbc pbd _comp) =
-- recompilation checking.
emptyBuildInfo
{ cSources = [ autogenDir </> unsafeMakeSymbolicPath "Gen.c"
, autogenDir </> unsafeMakeSymbolicPath "Gen2.c"]
, autogenDir </> unsafeMakeSymbolicPath "Gen2.c"
, autogenDir </> unsafeMakeSymbolicPath "DynDep.c"]
}
}
where
Expand All @@ -77,6 +78,7 @@ preBuildRules (PreBuildComponentInputs { buildingWhat = what, localBuildInfo = l
clbi = targetCLBI tgt
autogenDir = autogenComponentModulesDir lbi clbi
buildDir = componentBuildDir lbi clbi
mbWorkDir = mbWorkDirLBI lbi

runPpAction1 (PpInput {..}) = do
let verbosity = mkVerbosity defaultVerbosityHandles verbosityFlags
Expand Down Expand Up @@ -131,6 +133,18 @@ preBuildRules (PreBuildComponentInputs { buildingWhat = what, localBuildInfo = l
warn verbosity "Running MyPp4"
rewriteFileEx verbosity (getSymbolicPath genDir </> "GenLib.a") ""

runDynPpDependencyAction5 :: PpInput -> IO ([Dependency], ())
runDynPpDependencyAction5 (PpInput {..}) = do
let verbosity = mkVerbosity defaultVerbosityHandles verbosityFlags
warn verbosity "Running DynMyPpDependency5"
pure ([FileDependency $ Location sameDirectory (unsafeMakeSymbolicPath "DynDep.c")], ())

runDynPpAction5 :: PpInput -> () -> IO ()
runDynPpAction5 (PpInput {..}) () = do
let verbosity = mkVerbosity defaultVerbosityHandles verbosityFlags
warn verbosity "Running DynMyPp5"
copyFileToCwd verbosity mbWorkDir genDir (makeRelativePathEx "DynDep.c")

mkRule1 =
staticRule
(mkCommand (static Dict) (static runPpAction1) $ PpInput {genDir = autogenDir, ..})
Expand All @@ -157,16 +171,24 @@ preBuildRules (PreBuildComponentInputs { buildingWhat = what, localBuildInfo = l
[ ]
( Location autogenDir (unsafeMakeSymbolicPath "GenLib.a") NE.:| [] )

depsCmd = mkCommand (static Dict) (static runDynPpDependencyAction5) $ PpInput {genDir = autogenDir, ..}
genCmd = mkCommand (static Dict) (static runDynPpAction5) $ PpInput {genDir = autogenDir, ..}
output = Location autogenDir (unsafeMakeSymbolicPath "DynDep.c")
mkRule5 =
dynamicRule (static Dict) depsCmd genCmd [] (output NE.:| [])

r1 <- registerRule "MyPP1" mkRule1
void $ registerRule "MyPP2" (mkRule2 r1)
void $ registerRule "MyPP3" mkRule3
void $ registerRule "MyPP4" mkRule4
void $ registerRule "DynMyPP5" mkRule5

-- | Input to preprocessor command
data PpInput
= PpInput
{ verbosityFlags :: VerbosityFlags
, genDir :: SymbolicPath Pkg (Dir Source)
, mbWorkDir :: Maybe (SymbolicPath CWD (Dir Pkg))
}
deriving stock ( Show, Generic )
deriving anyclass Binary
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ Build profile: -w ghc-<GHCVER> -O1
In order, the following will be built:
- setup-hooks-non-hs-rules-test-0.1.0.0 (exe:NonHs) (first run)
Configuring setup-hooks-non-hs-rules-test-0.1.0.0...
Warning: Running DynMyPpDependency5
Warning: Running MyPp4
Warning: Running MyPp3
Warning: "cabal.dist/work/./dist/build/<ARCH>/ghc-<GHCVER>/setup-hooks-non-hs-rules-test-0.1.0.0/build/NonHs/autogen"
Warning: Running MyPp1
Warning: Running MyPp2
Warning: Running DynMyPp5
Preprocessing executable 'NonHs' for setup-hooks-non-hs-rules-test-0.1.0.0...
Building executable 'NonHs' for setup-hooks-non-hs-rules-test-0.1.0.0...
# cabal run
Expand All @@ -17,10 +19,12 @@ Build profile: -w ghc-<GHCVER> -O1
In order, the following will be built:
- setup-hooks-non-hs-rules-test-0.1.0.0 (exe:NonHs) (first run)
Configuring setup-hooks-non-hs-rules-test-0.1.0.0...
Warning: Running DynMyPpDependency5
Warning: Running MyPp4
Warning: Running MyPp3
Warning: "<ROOT>/cabal.dist/work/./inner/dist/build/<ARCH>/ghc-<GHCVER>/setup-hooks-non-hs-rules-test-0.1.0.0/build/NonHs/autogen"
Warning: Running MyPp1
Warning: Running MyPp2
Warning: Running DynMyPp5
Preprocessing executable 'NonHs' for setup-hooks-non-hs-rules-test-0.1.0.0...
Building executable 'NonHs' for setup-hooks-non-hs-rules-test-0.1.0.0...
21 changes: 21 additions & 0 deletions changelog.d/issue-12053
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
synopsis: Fixed binary format mismatch resulting in `runRuleDynDepsCmd` build error
packages: Cabal-hooks
prs: #12054
issues: #12053

description: {

A build containing a `dynamicRule` would fail with the following error:

```
Error: [Cabal-7125]
Failed to build hooks-0.1.0.0. The exception was:
Missing ByteString argument in 'ruleExecCmd'.
Run 'runRuleDynDepsCmd' on the rule to obtain this data.
```

This was caused by a mismatch between the binary formats used to encode and decode the rules.
The hook produced a result of type `([Dependency], LBS.ByteString)`, which was then encoded into a `Binary` blob.
However, `hooks-exe` decoded this data as `Maybe ([Dependency], LBS.ByteString)`, causing the build error.

}
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ runExternalPreBuildRules verbHandles hooksExe
SSystem
( \ rId cmd -> case cmd of
StaticRuleCommand {} -> return Nothing
DynamicRuleCommands {} -> hook "runPreBuildRuleDeps" (rId, cmd)
DynamicRuleCommands {} -> Just <$> hook "runPreBuildRuleDeps" (rId, cmd)
)
( \ rId cmd -> hook "runPreBuildRule" (rId, cmd) )
verbosity lbi tgt rulesMap
Expand Down
Loading