Skip to content

Commit 40d5152

Browse files
committed
Patch MSVC system includes to use -isystem
Monkey-patch ffi-clang MswinArgs to use -isystem instead of -I for auto-discovered system includes. This ensures clang treats MSVC STL headers as system headers, preventing the generator from processing internals like xstring. Remove once ffi-clang >= 0.15.1 is released.
1 parent 880123c commit 40d5152

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

lib/ruby-bindgen/parser.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ def initialize(inputter, clang_args, libclang: nil)
3636
require 'ffi/clang'
3737
require 'ruby-bindgen/refinements/cursor'
3838
require 'ruby-bindgen/refinements/type'
39+
require 'ruby-bindgen/refinements/mswin_args'
3940

4041
@index = FFI::Clang::Index.new(exclude_declarations_from_pch: false, display_diagnostics: true)
4142
end
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Compat patch for ffi-clang < 0.15.1 on MSVC.
2+
# Uses -isystem instead of -I for auto-discovered system includes so
3+
# that clang treats them as system headers (in_system_header? returns true).
4+
# Without this, the generator processes STL internals like xstring.
5+
#
6+
# Remove once ffi-clang >= 0.15.1 is released.
7+
8+
if defined?(FFI::Clang::MswinArgs)
9+
module FFI
10+
module Clang
11+
class MswinArgs < Args
12+
private
13+
14+
def extra_args(command_line_args)
15+
args = []
16+
17+
system_includes.each do |path|
18+
unless command_line_args.include?(path)
19+
args.push("-isystem", path)
20+
end
21+
end
22+
23+
args
24+
end
25+
end
26+
end
27+
end
28+
end

0 commit comments

Comments
 (0)