Tracking flags/compilers within a shake action

15 views
Skip to first unread message

Vanessa McHale

unread,
Mar 17, 2019, 3:29:07 PM3/17/19
to Shake build system

Hi all,

I often need to track compiler flags or the particular compiler used as part of a rule, e.g here: http://hackage.haskell.org/package/shake-c-0.4.0.0/docs/src/Development.Shake.C.html#dynLibR. Does shake have a way to track such flags as inputs in the same vein as need? As a trivial example, I would like for shake to rebuild all .o files when the rule changes to pass -O2 to the C compiler instead of -O0.

I attempted to use oracles at some point in the past, but I never got it working. (I'd also like for actions to be able to declare that they depend on particular flags the way they can declare they depend on particular files with need, though that is negotiable).

Cheers,
Vanessa McHale
signature.asc

Neil Mitchell

unread,
Mar 17, 2019, 5:58:49 PM3/17/19
to Vanessa McHale, Shake build system
Hi Vanessa,

Oracles are perfect for what you are after. To track something like
-O0 vs -O2 you'd need an oracle that tracks optimisation level:

newtype OptLevel = OptLevel() deriving (Show,Typeable,Eq,Hashable,Binary,NFData)
type instance RuleResult OptLevel= String
rules = do
addOracle $ \(OptLevel _) -> return $ if <whatever you use to
decide> then "-O0" else "-O2"
"foo.o" %> \_ -> do
level <- askOracle $ OptLevel ()

Now that's a tracked dependency which will update if anything changes.
That example is based on the docs for addOracle. Does that solve the
problem?

Thanks, Neil

Dan Fithian

unread,
Mar 17, 2019, 6:16:08 PM3/17/19
to Neil Mitchell, Vanessa McHale, Shake build system
+1, make sure you use Oracle and not Oracle cache because you want it to be reconsidered on every build.

Evan Laforge

unread,
Mar 19, 2019, 12:23:51 AM3/19/19
to Dan Fithian, Neil Mitchell, Vanessa McHale, Shake build system
For compiler flags, I use different build directories, i.e. so
build/opt (and build/opt/obj) has binaries and .o files built with -O,
build/debug without, build/profile with profiling flags, and
build/test with test flags. Some others, like build/doc and
build/hsc, have generated files that aren't dependent on compiler
flags.

The advantage of course is that I can keep them all cached at once,
and refreshing the debug or test build doesn't destroy the opt one.
The disadvantage of course is that it's just for a set of hardcoded
flags. But it's also not hard to add a new mode, I just need a new
(directory, flags) pair for it.
Reply all
Reply to author
Forward
0 new messages