Repository navigation
Expand file tree
/
Copy pathSetup.hs
More file actions
71 lines (64 loc) · 2.19 KB
/
Copy pathSetup.hs
File metadata and controls
71 lines (64 loc) · 2.19 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
65
66
67
68
69
70
71
module Main (main) where
import Control.Monad (when)
import Distribution.PackageDescription (
BuildInfo (extraLibs),
Library (libBuildInfo),
PackageDescription (library),
)
import Distribution.Simple (
buildHook,
defaultMainWithHooks,
preConf,
simpleUserHooks,
)
import Distribution.Simple.LocalBuildInfo (buildDir)
import Distribution.Simple.Setup (ConfigFlags (configConfigurationsFlags))
import Distribution.Types.Flag (lookupFlagAssignment, mkFlagName)
import System.Directory (copyFile, createDirectoryIfMissing, makeAbsolute)
import System.Environment (lookupEnv, setEnv)
import System.FilePath (searchPathSeparator, (</>))
import System.Process (callProcess)
main :: IO ()
main =
defaultMainWithHooks
simpleUserHooks
{ preConf = \arguments flags -> do
when (webrtcRequested flags) $ do
buildWebRTC
addWebRTCLibraryPath
preConf simpleUserHooks arguments flags
, buildHook = \packageDescription localBuildInfo hooks flags -> do
when (webrtcEnabled packageDescription) $ do
addWebRTCLibraryPath
installWebRTCArchive (buildDir localBuildInfo)
buildHook simpleUserHooks packageDescription localBuildInfo hooks flags
}
webrtcRequested :: ConfigFlags -> Bool
webrtcRequested flags =
lookupFlagAssignment (mkFlagName "webrtc") (configConfigurationsFlags flags)
== Just True
webrtcEnabled :: PackageDescription -> Bool
webrtcEnabled packageDescription =
maybe False (elem "hs_webrtc" . extraLibs . libBuildInfo) (library packageDescription)
buildWebRTC :: IO ()
buildWebRTC =
callProcess
"cargo"
[ "build"
, "--release"
, "--locked"
, "--manifest-path"
, "ffi/webrtc/Cargo.toml"
]
addWebRTCLibraryPath :: IO ()
addWebRTCLibraryPath = do
directory <- makeAbsolute "ffi/webrtc/target/release"
existing <- lookupEnv "LIBRARY_PATH"
let value = maybe directory (\path -> directory <> [searchPathSeparator] <> path) existing
setEnv "LIBRARY_PATH" value
installWebRTCArchive :: FilePath -> IO ()
installWebRTCArchive destination = do
createDirectoryIfMissing True destination
copyFile
"ffi/webrtc/target/release/libhs_webrtc.a"
(destination </> "libhs_webrtc.a")