-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathSetup.hs
More file actions
64 lines (57 loc) · 3.08 KB
/
Copy pathSetup.hs
File metadata and controls
64 lines (57 loc) · 3.08 KB
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
import Distribution.PackageDescription
import Distribution.Simple
import Distribution.Simple.LocalBuildInfo
import Distribution.Simple.Setup
import Distribution.Simple.Utils
import Distribution.System
import System.Directory
import System.Environment
import Data.Maybe
smartContractRoot = "../concordium-base/smart-contracts"
makeRust :: Args -> ConfigFlags -> IO HookedBuildInfo
makeRust args flags = do
let verbosity = fromFlag $ configVerbosity flags
rawSystemExit verbosity "mkdir" ["-p", smartContractRoot ++ "/lib"]
-- This way of determining the platform is not ideal.
notice verbosity "Calling 'cargo build'"
rawSystemExit
verbosity
"cargo"
["build", "--release", "--manifest-path", smartContractRoot ++ "/wasm-chain-integration/Cargo.toml", "--features=enable-ffi"]
case buildOS of
Windows -> do
notice verbosity "Copying concordium_smart_contract_engine library"
rawSystemExit verbosity "cp" ["-u", smartContractRoot ++ "/wasm-chain-integration/target/release/concordium_smart_contract_engine.dll", smartContractRoot ++ "/lib/"]
-- We remove the static library if it exists. Previously, it would have been copied
-- over, but now we want to just link with the dynamic library, so we ensure it is
-- removed.
rawSystemExit verbosity "rm" ["-f", smartContractRoot ++ "/lib/libconcordium_smart_contract_engine.a"]
_ -> do
rawSystemExit verbosity "ln" ["-s", "-f", "../wasm-chain-integration/target/release/libconcordium_smart_contract_engine.a", smartContractRoot ++ "/lib/"]
case buildOS of
OSX ->
rawSystemExit verbosity "ln" ["-s", "-f", "../wasm-chain-integration/target/release/libconcordium_smart_contract_engine.dylib", smartContractRoot ++ "/lib/libconcordium_smart_contract_engine.dylib"]
_ ->
rawSystemExit verbosity "ln" ["-s", "-f", "../wasm-chain-integration/target/release/libconcordium_smart_contract_engine.so", smartContractRoot ++ "/lib/libconcordium_smart_contract_engine.so"]
return emptyHookedBuildInfo
-- | On Windows, copy the DLL files to the binary install directory. This is to ensure that they
-- are accessible when running the binaries, tests and benchmarks.
copyDlls :: Args -> CopyFlags -> PackageDescription -> LocalBuildInfo -> IO ()
copyDlls _ flags pkgDescr lbi = case buildOS of
Windows -> do
let installDirs = absoluteComponentInstallDirs pkgDescr lbi (localUnitId lbi) copydest
let copyLib lib = do
rawSystemExit verbosity "cp" ["-u", smartContractRoot ++ "/lib/" ++ lib ++ ".dll", bindir installDirs]
notice verbosity $ "Copy " ++ lib ++ " to " ++ bindir installDirs
copyLib "concordium_smart_contract_engine"
_ -> return ()
where
distPref = fromFlag (copyDistPref flags)
verbosity = fromFlag (copyVerbosity flags)
copydest = fromFlag (copyDest flags)
main =
defaultMainWithHooks $
simpleUserHooks
{ preConf = makeRust,
postCopy = copyDlls
}