ClangSharpPInvokeGenerator emitting duplicate/out of order macro bindings
I am invoking
ClangSharpPInvokeGenerator
on a bunch of headers that altogether constitute ~30,000 #define
s and nothing else.
The important bit is that these constants are split over tens of headers that are to be amalgamated into a single class/file.
The settings are:
and the input .rsp
is (note that remap.rsp
contains no entries relating to this)
which results in a single CharacterModelElementId.cs
.
However, the output regularly contains redefinition errors of the type: The type 'CharacterModelElementId' already contains a definition for 'c104_elem_i_weapon_eff'
- even though there is no such duplication/redefinition in the source. Am I doing something prohibited/inadvisable by specifying multiple --file
args? Should I write my own header that #include
s all the ones I want to consume and only feed ClangSharpPInvokeGenerator
that?42 Replies
An example of the input header contents:
This is for version
20.1.2.1
since I'm not ready to migrate to .NET 10 yet.
The alarming bit is that the amount of produced errors varies by script run. I modeled the way I invoke it on TerraFX, and the script performing traversal/invocation is:
cc @Tanner Gooding
It also varies per script invocation which entries get duplicated, for what it's worth.
Redefinitions likely depend on how your files are setup and include eachother
if you process
a.h
and then separately process b.h
but that has #include a.h
then it may end up processing a "twice"
it's hard to say for sure without seeing the headers
for TerraFX, I typically give a single file that #include <...>
each file I need as a dependency or want to support
and then specify --traverse
to indicate what files I actually want to generate for, to avoid the recursive inclusion problemin this case, they are only a bunch of #defines with no #includes
occasionally, I also observe spurious failure to process, which has the following trace:
(never in the same header twice)
what version of the tool are you using and are you sure you have a matching version of libClang?
20.1.2.1
, and I haven't checked beyond simply installing the tool globally.3 has some patches, so I'd try with that first
but should otherwise work
are you on Windows?
I am on Windows, 11 24H2, and I think I went for this version because the later ones demand .NET 10
right, which is "production ready" and has a number of perf improvements around it
(plus just general fixes to the ClangSharp generator were made)
well issue is that linux distros, package managers and such don't have RCs
and I guess corporate policies could block non releases too
good thing you can get the binaries manually
and this isn't on Linux
and this is considered production ready so it shouldn't trigger any corporate policy
I would just have to install the RC1 SDK from the .NET website and then the tool can update?
yep
Sure, I'll go do that and report back; in the meantime, how I can check this thing you asked about having a matching libClang?
Or is that not applicable in this situation
it shouldn't matter for this case, since you're on Windows and 20.1 or later
does the tool not check if the libclang is matching automatically??
I would expect it to, but I am asking all the same since I'm unfamiliar with the subject matter
it does, but there are still quirks on Linux where that can get wonky
which is why I asked all the questions
i'd have assumed libclang does have some
get version
exportyes, but that isn't fully accurate to the degree needed
because they make breaks even in patch releases in some cases
does that export not provide the patch number?
Tool 'clangsharppinvokegenerator' was successfully updated from version '20.1.2.1' to version '20.1.2.3'.
- rerunning nowNot always, no. Again, the Linux builds get quite wonky and there's a ton of special handling required in some cases
which only goes so far
a throw of this form is now given
for the input header
another form of throw occurs for other headers:
(considering that 20.1.2.1 did give valid results after being run enough times to avoid the error, I wouldn't say the input is malformed)
there is still no consistency for which header will fail in which of these ways
does it repro if you only have a single
--file
?by single
--file
you mean one that #includes all current input, or literally just one of themliterally just one of them
it does not, in five invocations
so maybe I've got a leak or something for multiple files
that'd be a pita 😄
nor has any of the
generate.rsp
s I have that use single --file
args ever reproed
not to my recollection, anyway
would a workaround for this be to do what you do in TerraFX and #include-all in one headeryeah, just doing a single file that includes all the files and specifying those as traverse instead would workaround this
I just got a repro, but it requires release build
so let me see if I can figure it out
Looks like the in memory file buffer gets corrupted somehow
think I found the issue...
there's a
CXFile
to contents
cache
but the entry isn't removed after the file is closed
and Clang may then reuse the file handle:catfine:
I'm glad to hear it didn't take an eternity to find, at least
Thank you for looking into it
This should fix it: https://github.com/dotnet/ClangSharp/pull/637. I won't have a new release up until later, but if you want to build locally and use the tool instead of working around, that would be fine
it can wait for the next release
the important thing is that it is fixed, so I can rely on specifying
--file X Y Z W {...}
since I do have a lot of headers for which I'd have to manually apply the workaround
(and the sample was abridged; it's usually ~30 headers per "unit" or .rsp
, so it adds up)right, and the more files you have the more likely you'll hit a recycled id
thank you very much for taking the time