1+ {-# LANGUAGE CPP #-}
2+ {-# LANGUAGE DataKinds #-}
13{-# LANGUAGE MultiWayIf #-}
24{-# OPTIONS -Wall #-}
35module Main where
@@ -11,6 +13,17 @@ import Distribution.Simple.Utils
1113import Distribution.System
1214import Distribution.Verbosity
1315
16+ #if MIN_VERSION_Cabal(3,14,0)
17+ -- Note [Cabal 3.14]
18+ --
19+ -- If you change any path stuff, either test that the package still works with
20+ -- Cabal 3.12 or stop declaring support for it in accelerate.cabal. (If you do
21+ -- the latter, also remove all of the other conditionals in this file.)
22+ -- Note that supporting old versions of Cabal is useful for being able to run
23+ -- e.g. Accelerate on old GPU clusters, which is nice.
24+ import Distribution.Utils.Path (SymbolicPath , FileOrDir (Dir ), Pkg , CWD , interpretSymbolicPath )
25+ #endif
26+
1427import Control.Monad
1528import Data.Maybe
1629import System.Directory
@@ -44,13 +57,13 @@ preConfHook args config_flags = do
4457 -- Stack and cabal based builds require updating the submodules
4558 git <- doesDirectoryExist " .git"
4659 if git
47- then rawSystemExit verbosity " git" [" submodule" , " update" , " --init" , " --recursive" ]
60+ then rawSystemExit' verbosity " git" [" submodule" , " update" , " --init" , " --recursive" ]
4861 else do
4962 -- XXX: This must be kept up to date with the git submodule revision
5063 let archive = " v0.11.1.tar.gz"
5164 createDirectoryIfMissing True " cbits/tracy"
52- rawSystemExit verbosity " curl" [" -LO" , " https://github.com/wolfpld/tracy/archive/refs/tags/" ++ archive]
53- rawSystemExit verbosity " tar" [" -xzf" , archive, " -C" , " cbits/tracy" , " --strip-components" , " 1" ]
65+ rawSystemExit' verbosity " curl" [" -LO" , " https://github.com/wolfpld/tracy/archive/refs/tags/" ++ archive]
66+ rawSystemExit' verbosity " tar" [" -xzf" , archive, " -C" , " cbits/tracy" , " --strip-components" , " 1" ]
5467 removeFile archive
5568
5669 preConf simpleUserHooks args config_flags
@@ -69,8 +82,9 @@ postBuildHook args build_flags pkg_desc lbi = do
6982 Windows -> return () -- XXX TODO: Windows users get the dummy executable that just throws an error
7083 _ ->
7184 forM_ targets $ \ (hs_exe, c_dir, c_exe) -> do
72- let c_projdir = " cbits/tracy" </> c_dir
73- hs_builddir = buildDir lbi </> hs_exe
85+ let cwd = flagToMaybe (workingDirFlag build_flags)
86+ c_projdir = " cbits/tracy" </> c_dir
87+ hs_builddir = interpretSymbolicPath cwd (buildDir lbi) </> hs_exe
7488 hs_tmpdir = hs_builddir </> hs_exe ++ " -tmp"
7589
7690 -- TODO: This creates a separate build directory for each tracy
@@ -92,12 +106,12 @@ postBuildHook args build_flags pkg_desc lbi = do
92106 setupMessage verbosity (printf " Building executable '%s' from Tracy C++ sources for" hs_exe) (package pkg_desc)
93107
94108 -- We set LEGACY=1 so that tracy builds with X11 instead of Wayland.
95- rawSystemExit verbosity " cmake" [" -B" , hs_tmpdir, " -S" , c_projdir, " -DCMAKE_BUILD_TYPE=Release" , " -DLEGACY=1" ]
109+ rawSystemExit' verbosity " cmake" [" -B" , hs_tmpdir, " -S" , c_projdir, " -DCMAKE_BUILD_TYPE=Release" , " -DLEGACY=1" ]
96110
97111 -- Build in parallel with 2 jobs because likely, accelerate is one of
98112 -- the last dependencies in a build, so we aren't stealing CPU time
99113 -- from other packages, and tracy takes way too long to build
100- rawSystemExit verbosity " cmake" [" --build" , hs_tmpdir, " --config" , " Release" , " -j" , " 2" ]
114+ rawSystemExit' verbosity " cmake" [" --build" , hs_tmpdir, " --config" , " Release" , " -j" , " 2" ]
101115
102116 -- Copy, not rename, to prevent cmake from linking again on the next
103117 -- reconfigure
@@ -109,3 +123,23 @@ tracyMode :: ConfigFlags -> Bool
109123tracyMode config_flags =
110124 fromMaybe False $
111125 lookupFlagAssignment (mkFlagName " tracy" ) (configConfigurationsFlags config_flags)
126+
127+
128+ rawSystemExit' :: Verbosity -> FilePath -> [String ] -> IO ()
129+
130+ #if MIN_VERSION_Cabal(3,14,0)
131+ rawSystemExit' verb = rawSystemExit verb Nothing
132+
133+ workingDirFlag :: BuildFlags -> Flag (SymbolicPath CWD ('Dir Pkg ))
134+ workingDirFlag = setupWorkingDir . buildCommonFlags
135+
136+ -- interpretSymbolicPath is an actual useful function in Cabal-3.14
137+ #else
138+ rawSystemExit' = rawSystemExit
139+
140+ workingDirFlag :: BuildFlags -> Flag ()
141+ workingDirFlag _ = NoFlag
142+
143+ interpretSymbolicPath :: Maybe CWDPath -> FilePath -> FilePath
144+ interpretSymbolicPath _ = id
145+ #endif
0 commit comments