-
Notifications
You must be signed in to change notification settings - Fork 3
/
Setup.hs
100 lines (91 loc) · 3.07 KB
/
Setup.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import Control.Monad
import Data.Maybe
import qualified Distribution.PackageDescription as PD
import Distribution.Simple
( Args
, UserHooks (confHook, preConf)
, defaultMainWithHooks
, simpleUserHooks
)
import Distribution.Simple.Program
( ghcProgram
)
import Distribution.Simple.LocalBuildInfo
( LocalBuildInfo (localPkgDescr)
, buildDir
, compiler
)
import Distribution.Simple.Setup
( BuildFlags (buildVerbosity)
, ConfigFlags (configVerbosity)
, CleanFlags(..)
, fromFlag
)
import Distribution.Simple.UserHooks
( UserHooks (buildHook, confHook, cleanHook)
)
import Distribution.Simple.Utils
( notice
, copyFileVerbose
, createDirectoryIfMissingVerbose
, rawSystemExit
, info
)
import System.Directory (getCurrentDirectory)
import Distribution.Text (display)
import Distribution.Simple.Compiler
import Distribution.System (buildPlatform, buildOS, OS(..))
import Distribution.Simple.BuildPaths
( mkGenericSharedBundledLibName
, mkGenericSharedLibName
, mkGenericStaticLibName
, dllExtension
)
main :: IO ()
main =
defaultMainWithHooks
simpleUserHooks { buildHook = rustBuildHook }
rustBuildHook
:: PD.PackageDescription
-> LocalBuildInfo
-> UserHooks
-> BuildFlags
-> IO ()
rustBuildHook description localBuildInfo hooks flags = do
-- run Rust build
-- FIXME add cargo and rust to program db during configure step
-- FIXME: add `--target $TARGET` flag to support cross-compiling to $TARGET
notice verbosity "Call `cargo build --release` to build a dependency written in Rust"
rawSystemExit (fromFlag $ buildVerbosity flags) "cargo"
[ "build"
, "--release"
, "--target-dir"
, rustTargetDir
]
-- Install build results into cabal build directory
createDirectoryIfMissingVerbose verbosity True targetBuildDir
copyFileVerbose verbosity staticSource staticTarget
copyFileVerbose verbosity dynSource dynTarget
-- seems to be needed for local use of template haskell
copyFileVerbose verbosity dynSource dynTarget_
when (buildOS == OSX) $
rawSystemExit verbosity "install_name_tool"
[ "-id"
, "@rpath/" <> mkGenericSharedBundledLibName buildPlatform (compilerId c) targetLibname
, dynTarget
]
info verbosity "rustc compilation succeeded"
buildHook simpleUserHooks description localBuildInfo hooks flags
where
verbosity = fromFlag $ buildVerbosity flags
c = compiler localBuildInfo
sourceLibname = "plonk_verify"
targetLibname = "C" <> sourceLibname
rustTargetDir = buildDir localBuildInfo <> "/rust-target"
sourceBuildDir = rustTargetDir <> "/release"
targetBuildDir = buildDir localBuildInfo
staticSource = sourceBuildDir <> "/" <> mkGenericStaticLibName sourceLibname
staticTarget = targetBuildDir <> "/" <> mkGenericStaticLibName targetLibname
dynSource = sourceBuildDir <> "/" <> "lib" <> sourceLibname <> "." <> dllExtension buildPlatform
dynTarget = targetBuildDir <> "/" <> mkGenericSharedBundledLibName buildPlatform (compilerId c) targetLibname
dynTarget_ = targetBuildDir <> "/" <> mkGenericSharedLibName buildPlatform (compilerId c) targetLibname