git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
C++: add xcode support
f6c70bcAndy Arvanitis
pcc/Main.hs+9
@@ -54,6 +54,7 @@ data PCCMakeOptions = PCCMakeOptions
54 , pccmOpts :: P.Options
54 , pccmOpts :: P.Options
55 , pccmUsePrefix :: Bool
55 , pccmUsePrefix :: Bool
56 , pccmJSONErrors :: Bool
56 , pccmJSONErrors :: Bool
57+ , pccmXcode :: Bool
57 }
58 }
58
59
59-- | Argumnets: verbose, use JSON, warnings, errors
60-- | Argumnets: verbose, use JSON, warnings, errors
@@ -77,6 +78,8 @@ printWarningsAndErrors verbose True warnings errors = do
77compile :: PCCMakeOptions -> IO ()
78compile :: PCCMakeOptions -> IO ()
78compile PCCMakeOptions{..} = do
79compile PCCMakeOptions{..} = do
79 input <- globWarningOnMisses (unless pccmJSONErrors . warnFileTypeNotFound) pccmInput
80 input <- globWarningOnMisses (unless pccmJSONErrors . warnFileTypeNotFound) pccmInput
81+ when pccmXcode $ do
82+ generateXcodefile
80 when (null input && not pccmJSONErrors) $ do
83 when (null input && not pccmJSONErrors) $ do
81 generatePackagefile
84 generatePackagefile
82 generateMakefile
85 generateMakefile
@@ -165,6 +168,11 @@ dumpCoreFn = switch $
165 long "dump-corefn"
168 long "dump-corefn"
166 <> help "Dump the (functional) core representation of the compiled code at output/*/corefn.json"
169 <> help "Dump the (functional) core representation of the compiled code at output/*/corefn.json"
167
170
171+xcode :: Parser Bool
172+xcode = switch $
173+ long "xcode"
174+ <> help "Generate support files for Xcode"
175+
168options :: Parser P.Options
176options :: Parser P.Options
169options = P.Options <$> noTco
177options = P.Options <$> noTco
170 <*> noMagicDo
178 <*> noMagicDo
@@ -181,6 +189,7 @@ pccMakeOptions = PCCMakeOptions <$> many inputFile
181 <*> options
189 <*> options
182 <*> (not <$> noPrefix)
190 <*> (not <$> noPrefix)
183 <*> jsonErrors
191 <*> jsonErrors
192+ <*> xcode
184
193
185main :: IO ()
194main :: IO ()
186main = do
195main = do
pcc/Makefile+1−1
@@ -15,7 +15,7 @@
15# You can also edit the generated version of this file directly.
15# You can also edit the generated version of this file directly.
16#
16#
17PCC := {{path}}/pcc
17PCC := {{path}}/pcc
18−PSC_PACKAGE := psc-package
18+PSC_PACKAGE := {{path}}/psc-package
19PURESCRIPT_PKGS := .psc-package
19PURESCRIPT_PKGS := .psc-package
20PURESCRIPT_SRC := src
20PURESCRIPT_SRC := src
21OUTPUT := output
21OUTPUT := output
pcc/Makefile.hs+26−6
@@ -26,13 +26,13 @@ import qualified Data.ByteString.Char8 as B
26
26
27generateMakefile :: IO ()
27generateMakefile :: IO ()
28generateMakefile = do
28generateMakefile = do
29− makefileExists <- doesFileExist "Makefile"
29+ makefileExists <- doesFileExist makefilename
30 when (not makefileExists) $ do
30 when (not makefileExists) $ do
31 let makefile = $(embedFile "pcc/Makefile")
31 let makefile = $(embedFile "pcc/Makefile")
32 exePath <- getExecutablePath
32 exePath <- getExecutablePath
33 putStrLn ""
33 putStrLn ""
34− putStrLn $ "Generating Makefile... " ++ "pcc executable location " ++ exePath
34+ putStrLn $ "Generating " ++ makefilename ++ "... " ++ "pcc executable location " ++ exePath
35− writeFile "Makefile" . T.unpack $
35+ writeFile makefilename . T.unpack $
36 T.replace
36 T.replace
37 pathPlaceholder
37 pathPlaceholder
38 (T.pack $ takeDirectory exePath)
38 (T.pack $ takeDirectory exePath)
@@ -48,14 +48,34 @@ generateMakefile = do
48
48
49generatePackagefile :: IO ()
49generatePackagefile :: IO ()
50generatePackagefile = do
50generatePackagefile = do
51− pkgfileExists <- doesFileExist "psc-package.json"
51+ pkgfileExists <- doesFileExist packagefilename
52 when (not pkgfileExists) $ do
52 when (not pkgfileExists) $ do
53 let pkgfile = $(embedFile "pcc/psc-package.json")
53 let pkgfile = $(embedFile "pcc/psc-package.json")
54 putStrLn ""
54 putStrLn ""
55− putStrLn "Generating psc-package.json..."
55+ putStrLn $ "Generating " ++ packagefilename ++ "..."
56− writeFile "psc-package.json" $ B.unpack pkgfile
56+ writeFile packagefilename $ B.unpack pkgfile
57 putStrLn "Done"
57 putStrLn "Done"
58 putStrLn "Use the 'psc-package' utility to install or update packages."
58 putStrLn "Use the 'psc-package' utility to install or update packages."
59
59
60+generateXcodefile :: IO ()
61+generateXcodefile = do
62+ xcodefileExists <- doesFileExist xcodefilename
63+ when (not xcodefileExists) $ do
64+ let xcodefile = $(embedFile "pcc/psc-xcode.sh")
65+ putStrLn ""
66+ putStrLn $ "Generating " ++ xcodefilename ++ "..."
67+ writeFile xcodefilename $ B.unpack xcodefile
68+ putStrLn "Done"
69+ putStrLn "Add this file to an Xcode 'Run Script' build phase."
70+
71+makefilename :: String
72+makefilename = "Makefile"
73+
74+packagefilename :: String
75+packagefilename = "psc-package.json"
76+
77+xcodefilename :: String
78+xcodefilename = "psc-xcode.sh"
79+
60pathPlaceholder :: T.Text
80pathPlaceholder :: T.Text
61pathPlaceholder = "{{path}}"
81pathPlaceholder = "{{path}}"
pcc/psc-xcode.shnew file+48
@@ -0,0 +1,48 @@
1+# Xcode support script. Intended to be added to and called from "Run Script" build phase.
2+#
3+#!/bin/sh
4+
5+echo "CONFIGURATION =" "$CONFIGURATION"
6+echo "ARCHITECTURES =" "$ARCHS"
7+
8+IS_DEBUG="$PROJECT_TEMP_DIR/is_debug"
9+IS_RELEASE="$PROJECT_TEMP_DIR/is_release"
10+
11+if [[ "$CONFIGURATION" == "Debug" ]] ; then
12+ if [ ! -f "$IS_DEBUG" ] ; then
13+ make clean
14+ touch "$IS_DEBUG"
15+ fi
16+ rm "$IS_RELEASE" > /dev/null 2>&1 || true
17+ OBJECT_TYPE=debug-object
18+else
19+ if [ ! -f "$IS_RELEASE" ] ; then
20+ make clean
21+ touch "$IS_RELEASE"
22+ fi
23+ rm "$IS_DEBUG" > /dev/null 2>&1 || true
24+ OBJECT_TYPE=release-object
25+fi
26+
27+## Create compiler switches for architectures
28+#
29+for arch_ in $ARCHS ; do
30+ ARCH_OPTS+="-arch $arch_ "
31+ if ! file output/bin/purescript.o | grep -q $arch_; then
32+ make clean
33+ fi
34+ # TODO: make this more future-proof
35+ # Note: -flto optimization causes problems with the source-level
36+ # debugger. Disable bitcode temporarily if necessary.
37+ if [[ $ENABLE_BITCODE == YES && $arch == arm64 ]] ; then
38+ FLTO="-flto"
39+ fi
40+done
41+
42+## Look for psc-package, in case it's already in the PATH
43+#
44+if [ -x "$(command -v psc-package)" ] ; then
45+ PSC_PKG="PSC_PACKAGE=$(command -v psc-package)"
46+fi
47+
48+make $OBJECT_TYPE ${PSC_PKG} CXXFLAGS="$ARCH_OPTS $FLTO -isysroot $SDKROOT" LD="clang -Wl,-r -nostdlib $ARCH_OPTS" -j`sysctl -n hw.ncpu`