Skip to content

Commit

Permalink
modefilefree: RFC: Get C flags from toolchain
Browse files Browse the repository at this point in the history
Summary:
Alrighty, so I'm starting with what may be the most ambitious proposal.

Haskell compilation requires passing approximately all of the C compiler flags to ghc, prefixed with `-optl`, `-optc`, or `-opta`. That was previously implemented in gen_modes.py by just using the compiler flags there. This diff proposes to instead depend on the CXX toolchain directly from the haskell toolchain and get access to the flags that way.

The first problem with this is that the flags we need are just exposed in the cxx toolchain as a `cmd_args`, but that doesn't provide a convenient way to filter out the subset of the flags that we want to remove, so we have to do some `dynamic_outputs` shenanigans. Not super correct, but not the biggest problem either.

The bigger issue though is that I don't actually know what the right plan for handling this is. Specifically, it's obvious that "just pass all of the C flags to ghc" is not correct (especially since this is using gcc even on clang toolchains if I'm reading things right). But I don't know how I'm supposed to distinguish either. This is particularly concerning since we expect to move more things to the toolchain in the future - what happens if sanitizer flags start showing up here? How do we make sure that people changing cxx toolchain flags in the future don't have to start learning about ghc oddities?

So if there's a better suggestion for how to do this than "assume everything from the C++ toolchain works and then filter a couple things out," I'm all ears. This is just the first proposal.

Reviewed By: scottcao

Differential Revision: D68888352

fbshipit-source-id: 1a2aa8442f341078436745f882d8250fa514b2e5
  • Loading branch information
JakobDegen authored and facebook-github-bot committed Feb 5, 2025
1 parent baa9f95 commit 88da058
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
8 changes: 6 additions & 2 deletions prelude/haskell/compile.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,15 @@ def compile_args(
link_style: LinkStyle,
enable_profiling: bool,
pkgname = None,
suffix: str = "") -> CompileArgsInfo:
suffix: str = "",
for_haddock: bool = False) -> CompileArgsInfo:
haskell_toolchain = ctx.attrs._haskell_toolchain[HaskellToolchainInfo]

compile_cmd = cmd_args()
compile_cmd.add(haskell_toolchain.compiler_flags)
if for_haddock and haskell_toolchain.compiler_flags_for_haddock != None:
compile_cmd.add(haskell_toolchain.compiler_flags_for_haddock)
else:
compile_cmd.add(haskell_toolchain.compiler_flags)

# Some rules pass in RTS (e.g. `+RTS ... -RTS`) options for GHC, which can't
# be parsed when inside an argsfile.
Expand Down
1 change: 1 addition & 0 deletions prelude/haskell/haskell_haddock.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def haskell_haddock_lib(ctx: AnalysisContext, pkgname: str) -> Provider:
enable_profiling = False,
suffix = "-haddock",
pkgname = pkgname,
for_haddock = True,
)

cmd = cmd_args(haskell_toolchain.haddock)
Expand Down
1 change: 1 addition & 0 deletions prelude/haskell/toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ HaskellToolchainInfo = provider(
"linker": provider_field(typing.Any, default = None),
"linker_flags": provider_field(typing.Any, default = None),
"haddock": provider_field(typing.Any, default = None),
"compiler_flags_for_haddock": provider_field(cmd_args | None, default = None),
"compiler_major_version": provider_field(typing.Any, default = None),
"package_name_prefix": provider_field(typing.Any, default = None),
"packager": provider_field(typing.Any, default = None),
Expand Down

0 comments on commit 88da058

Please sign in to comment.