Skip to content

Commit 7b191a7

Browse files
Add command line options to specify the compiler
1 parent 9dee51c commit 7b191a7

File tree

2 files changed

+91
-43
lines changed

2 files changed

+91
-43
lines changed

bootstrap/src/Fpm.hs

Lines changed: 84 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import Control.Monad.Extra ( concatMapM
1616
, forM_
1717
, when
1818
)
19-
import Data.Hashable (hash)
19+
import Data.Hashable ( hash )
2020
import Data.List ( isSuffixOf
2121
, find
2222
, nub
@@ -46,6 +46,8 @@ import Options.Applicative ( Parser
4646
, metavar
4747
, optional
4848
, progDesc
49+
, short
50+
, showDefault
4951
, strArgument
5052
, strOption
5153
, subparser
@@ -77,14 +79,18 @@ data Arguments =
7779
, newWithLib :: Bool
7880
}
7981
| Build
80-
{ buildRelease :: Bool }
82+
{ buildRelease :: Bool
83+
, buildCompiler :: FilePath
84+
}
8185
| Run
8286
{ runRelease :: Bool
87+
, runCompiler :: FilePath
8388
, runTarget :: Maybe String
8489
, runArgs :: Maybe String
8590
}
8691
| Test
8792
{ testRelease :: Bool
93+
, testCompiler :: FilePath
8894
, testTarget :: Maybe String
8995
, testArgs :: Maybe String
9096
}
@@ -365,8 +371,19 @@ newArguments =
365371
<*> switch (long "lib" <> help "Include a library")
366372

367373
buildArguments :: Parser Arguments
368-
buildArguments = Build <$> switch
369-
(long "release" <> help "Build with optimizations instead of debugging")
374+
buildArguments =
375+
Build
376+
<$> switch
377+
( long "release"
378+
<> help "Build with optimizations instead of debugging"
379+
)
380+
<*> strOption
381+
( long "compiler"
382+
<> metavar "COMPILER"
383+
<> value "gfortran"
384+
<> help "specify the compiler to use"
385+
<> showDefault
386+
)
370387

371388
runArguments :: Parser Arguments
372389
runArguments =
@@ -375,6 +392,13 @@ runArguments =
375392
( long "release"
376393
<> help "Build with optimizations instead of debugging"
377394
)
395+
<*> strOption
396+
( long "compiler"
397+
<> metavar "COMPILER"
398+
<> value "gfortran"
399+
<> help "specify the compiler to use"
400+
<> showDefault
401+
)
378402
<*> optional
379403
(strArgument
380404
(metavar "TARGET" <> help "Name of the executable to run")
@@ -389,6 +413,13 @@ testArguments =
389413
( long "release"
390414
<> help "Build with optimizations instead of debugging"
391415
)
416+
<*> strOption
417+
( long "compiler"
418+
<> metavar "COMPILER"
419+
<> value "gfortran"
420+
<> help "specify the compiler to use"
421+
<> showDefault
422+
)
392423
<*> optional
393424
(strArgument (metavar "TARGET" <> help "Name of the test to run"))
394425
<*> optional (strArgument (metavar "ARGS" <> help "Arguments to the test"))
@@ -498,49 +529,53 @@ toml2AppSettings tomlSettings args = do
498529
Run { runRelease = r } -> r
499530
Test { testRelease = r } -> r
500531
let projectName = tomlSettingsProjectName tomlSettings
501-
let compiler = "gfortran"
532+
let compiler = case args of
533+
Build { buildCompiler = c } -> c
534+
Run { runCompiler = c } -> c
535+
Test { testCompiler = c } -> c
502536
librarySettings <- getLibrarySettings $ tomlSettingsLibrary tomlSettings
503537
executableSettings <- getExecutableSettings
504538
(tomlSettingsExecutables tomlSettings)
505539
projectName
506540
testSettings <- getTestSettings $ tomlSettingsTests tomlSettings
507-
let flags = if release
508-
then
509-
[ "-Wall"
510-
, "-Wextra"
511-
, "-Wimplicit-interface"
512-
, "-fPIC"
513-
, "-fmax-errors=1"
514-
, "-O3"
515-
, "-march=native"
516-
, "-ffast-math"
517-
, "-funroll-loops"
518-
]
519-
else
520-
[ "-Wall"
521-
, "-Wextra"
522-
, "-Wimplicit-interface"
523-
, "-fPIC"
524-
, "-fmax-errors=1"
525-
, "-g"
526-
, "-fbounds-check"
527-
, "-fcheck-array-temporaries"
528-
, "-fbacktrace"
529-
]
530-
buildPrefix <- makeBuildPrefix compiler flags
541+
let flags = if compiler == "gfortran"
542+
then if release
543+
then
544+
[ "-Wall"
545+
, "-Wextra"
546+
, "-Wimplicit-interface"
547+
, "-fPIC"
548+
, "-fmax-errors=1"
549+
, "-O3"
550+
, "-march=native"
551+
, "-ffast-math"
552+
, "-funroll-loops"
553+
]
554+
else
555+
[ "-Wall"
556+
, "-Wextra"
557+
, "-Wimplicit-interface"
558+
, "-fPIC"
559+
, "-fmax-errors=1"
560+
, "-g"
561+
, "-fbounds-check"
562+
, "-fcheck-array-temporaries"
563+
, "-fbacktrace"
564+
]
565+
else []
566+
buildPrefix <- makeBuildPrefix compiler flags
531567
let dependencies = tomlSettingsDependencies tomlSettings
532568
let devDependencies = tomlSettingsDevDependencies tomlSettings
533-
return AppSettings
534-
{ appSettingsCompiler = compiler
535-
, appSettingsProjectName = projectName
536-
, appSettingsBuildPrefix = buildPrefix
537-
, appSettingsFlags = flags
538-
, appSettingsLibrary = librarySettings
539-
, appSettingsExecutables = executableSettings
540-
, appSettingsTests = testSettings
541-
, appSettingsDependencies = dependencies
542-
, appSettingsDevDependencies = devDependencies
543-
}
569+
return AppSettings { appSettingsCompiler = compiler
570+
, appSettingsProjectName = projectName
571+
, appSettingsBuildPrefix = buildPrefix
572+
, appSettingsFlags = flags
573+
, appSettingsLibrary = librarySettings
574+
, appSettingsExecutables = executableSettings
575+
, appSettingsTests = testSettings
576+
, appSettingsDependencies = dependencies
577+
, appSettingsDevDependencies = devDependencies
578+
}
544579

545580
getLibrarySettings :: Maybe Library -> IO (Maybe Library)
546581
getLibrarySettings maybeSettings = case maybeSettings of
@@ -596,9 +631,15 @@ makeBuildPrefix compiler flags = do
596631
-- Probably version, and make sure to not include path to the compiler
597632
versionInfo <- readProcess compiler ["--version"] []
598633
let compilerName = last (splitDirectories compiler)
599-
let versionHash = hash versionInfo
600-
let flagsHash = hash flags
601-
return $ "build" </> compilerName ++ "_" ++ show versionHash ++ "_" ++ show flagsHash
634+
let versionHash = hash versionInfo
635+
let flagsHash = hash flags
636+
return
637+
$ "build"
638+
</> compilerName
639+
++ "_"
640+
++ show versionHash
641+
++ "_"
642+
++ show flagsHash
602643

603644
{-
604645
Fetching the dependencies is done on a sort of breadth first approach. All

bootstrap/test/Spec.hs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ testHelloWorld :: IO ()
2020
testHelloWorld =
2121
withCurrentDirectory (example_path </> "hello_world") $ start $ Run
2222
{ runRelease = False
23+
, runCompiler = "gfortran"
2324
, runTarget = Nothing
2425
, runArgs = Nothing
2526
}
@@ -28,6 +29,7 @@ testHelloComplex :: IO ()
2829
testHelloComplex =
2930
withCurrentDirectory (example_path </> "hello_complex") $ start $ Test
3031
{ testRelease = False
32+
, testCompiler = "gfortran"
3133
, testTarget = Nothing
3234
, testArgs = Nothing
3335
}
@@ -36,6 +38,7 @@ testHelloFpm :: IO ()
3638
testHelloFpm =
3739
withCurrentDirectory (example_path </> "hello_fpm") $ start $ Run
3840
{ runRelease = False
41+
, runCompiler = "gfortran"
3942
, runTarget = Nothing
4043
, runArgs = Nothing
4144
}
@@ -44,6 +47,7 @@ testCircular :: IO ()
4447
testCircular =
4548
withCurrentDirectory (example_path </> "circular_example") $ start $ Test
4649
{ testRelease = False
50+
, testCompiler = "gfortran"
4751
, testTarget = Nothing
4852
, testArgs = Nothing
4953
}
@@ -52,12 +56,14 @@ testWithMakefile :: IO ()
5256
testWithMakefile =
5357
withCurrentDirectory (example_path </> "with_makefile") $ start $ Build
5458
{ buildRelease = False
59+
, buildCompiler = "gfortran"
5560
}
5661

5762
testMakefileComplex :: IO ()
5863
testMakefileComplex =
5964
withCurrentDirectory (example_path </> "makefile_complex") $ start $ Run
6065
{ runRelease = False
66+
, runCompiler = "gfortran"
6167
, runTarget = Nothing
6268
, runArgs = Nothing
6369
}
@@ -66,4 +72,5 @@ testSubmodule :: IO ()
6672
testSubmodule =
6773
withCurrentDirectory (example_path </> "submodules") $ start $ Build
6874
{ buildRelease = False
75+
, buildCompiler = "gfortran"
6976
}

0 commit comments

Comments
 (0)