Skip to content

Commit 8283499

Browse files
authored
Merge pull request #1311 from well-typed/bolt12/bump-libclang
Bump libclang and compare its versions
2 parents 17fc95d + 9a82d7e commit 8283499

File tree

5 files changed

+66
-11
lines changed

5 files changed

+66
-11
lines changed

cabal.project.base

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ index-state: 2025-09-16T04:55:58Z
44
source-repository-package
55
type: git
66
location: https://github.com/well-typed/libclang
7-
tag: 41f70874b0f803366144059c0ed0f65809e8c385
7+
tag: b62972c5a4227f92ac7af7df60af52f9ead7bd35

flake.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

hs-bindgen/hs-bindgen.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ library internal
109109
HsBindgen.Cache
110110
HsBindgen.Clang
111111
HsBindgen.Clang.BuiltinIncDir
112+
HsBindgen.Clang.CompareVersions
112113
HsBindgen.Clang.ExtraClangArgs
113114
HsBindgen.Config.ClangArgs
114115
HsBindgen.Config.FixCandidate

hs-bindgen/src-internal/HsBindgen/Boot.hs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import Clang.Args
1313
import HsBindgen.BindingSpec
1414
import HsBindgen.Cache
1515
import HsBindgen.Clang.BuiltinIncDir
16+
import HsBindgen.Clang.CompareVersions (CompareVersionsMsg,
17+
compareClangVersions)
1618
import HsBindgen.Clang.ExtraClangArgs
1719
import HsBindgen.Config.ClangArgs (ClangArgsConfig)
1820
import HsBindgen.Config.ClangArgs qualified as ClangArgs
@@ -102,6 +104,7 @@ getClangArgs tracer config = do
102104
fst <$> ClangArgs.target config
103105
mBuiltinIncDir <- getBuiltinIncDir (contramap BootBuiltinIncDir tracer) $
104106
ClangArgs.builtinIncDir config
107+
compareClangVersions (contramap BootCompareClangVersions tracer)
105108
either throwIO return
106109
. ClangArgs.getClangArgs
107110
. applyExtraClangArgs extraClangArgs
@@ -152,12 +155,13 @@ instance IsTrace Level BootStatusMsg where
152155

153156
-- | Boot trace messages
154157
data BootMsg =
155-
BootBackendConfig BackendConfigMsg
156-
| BootBindingSpec BindingSpecMsg
157-
| BootBuiltinIncDir BuiltinIncDirMsg
158-
| BootExtraClangArgs ExtraClangArgsMsg
159-
| BootHashIncludeArg HashIncludeArgMsg
160-
| BootStatus BootStatusMsg
161-
| BootCache (SafeTrace CacheMsg)
158+
BootBackendConfig BackendConfigMsg
159+
| BootBindingSpec BindingSpecMsg
160+
| BootBuiltinIncDir BuiltinIncDirMsg
161+
| BootExtraClangArgs ExtraClangArgsMsg
162+
| BootHashIncludeArg HashIncludeArgMsg
163+
| BootCompareClangVersions CompareVersionsMsg
164+
| BootStatus BootStatusMsg
165+
| BootCache (SafeTrace CacheMsg)
162166
deriving stock (Show, Generic)
163167
deriving anyclass (PrettyForTrace, IsTrace Level)
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
2+
module HsBindgen.Clang.CompareVersions where
3+
4+
import Text.SimplePrettyPrint ((<+>))
5+
import Text.SimplePrettyPrint qualified as PP
6+
7+
import Clang.Version (clangVersionCompileTime, clang_getClangVersion)
8+
9+
import HsBindgen.Imports
10+
import HsBindgen.Util.Tracer
11+
12+
{-------------------------------------------------------------------------------
13+
Trace messages
14+
-------------------------------------------------------------------------------}
15+
16+
data CompareVersionsMsg =
17+
CompileTimeAndRuntimeVersionMismatch Text Text
18+
deriving stock (Show)
19+
20+
instance PrettyForTrace CompareVersionsMsg where
21+
prettyForTrace = \case
22+
CompileTimeAndRuntimeVersionMismatch compileTimeVersion runtimeVersion ->
23+
PP.hangs' "clang version mismatch:" 2 [
24+
"clang compile time version:" <+> PP.textToCtxDoc compileTimeVersion
25+
, "clang runtime version: " <+> PP.textToCtxDoc runtimeVersion
26+
]
27+
28+
instance IsTrace Level CompareVersionsMsg where
29+
getDefaultLogLevel = \case
30+
CompileTimeAndRuntimeVersionMismatch _ _ -> Warning
31+
32+
getSource = const HsBindgen
33+
34+
getTraceId = const "compare-clang-versions"
35+
36+
{-------------------------------------------------------------------------------
37+
Comparison functions
38+
-------------------------------------------------------------------------------}
39+
40+
-- | Get
41+
--
42+
-- @clang -print-file-name=include@ is called to get the builtin include
43+
-- directory.
44+
compareClangVersions :: Tracer CompareVersionsMsg -> IO ()
45+
compareClangVersions tracer = do
46+
let compileTimeVersion = clangVersionCompileTime
47+
runtimeVersion <- liftIO clang_getClangVersion
48+
when (compileTimeVersion /= runtimeVersion) $
49+
traceWith tracer (CompileTimeAndRuntimeVersionMismatch compileTimeVersion runtimeVersion)
50+

0 commit comments

Comments
 (0)