Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing generate-file-scoped-namespaces results in extra curly brace being added to end of file #555

Open
kkukshtel opened this issue May 24, 2024 · 3 comments

Comments

@kkukshtel
Copy link
Contributor

I've been having this issue for as long as I can remember and I finally decided to track it down and it seems to be manifesting when declaring generate-file-scoped-namespaces.

Here's a pretty "standard" rsp that I use for a pretty simple file here (sokol_log.h)

--config
latest-codegen
single-file
generate-aggressive-inlining
generate-file-scoped-namespaces
log-exclusions
log-potential-typedef-remappings
log-visited-files
generate-cpp-attributes
--additional
-Wno-ignored-attributes
-Wno-nullability-completeness
-Wunused-function

--include-directory
C:/Program Files (x86)/Windows Kits/10/Include/10.0.22621.0/ucrt
./libs/sokol/src/sokol
./libs/sokol/src/
--define-macro
SOKOL_DLL
SOKOL_NO_ENTRY
SOKOL_TRACE_HOOKS
--namespace
Zinc.Internal.Sokol
--libraryPath
sokol

--file
./libs/sokol/src/sokol/sokol_log.h
--methodClassName
Log
--output
./out/src/generated/lib/sokol/Sokol.Log.cs

Here's the corresponding output (notice the extra brace):

using System.Runtime.InteropServices;

namespace Zinc.Internal.Sokol;

public static unsafe partial class Log
{
    [DllImport("sokol", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
    public static extern void slog_func([NativeTypeName("const char *")] sbyte* tag, [NativeTypeName("uint32_t")] uint log_level, [NativeTypeName("uint32_t")] uint log_item, [NativeTypeName("const char *")] sbyte* message, [NativeTypeName("uint32_t")] uint line_nr, [NativeTypeName("const char *")] sbyte* filename, void* user_data);
}
}

And without:

using System.Runtime.InteropServices;

namespace Zinc.Internal.Sokol;

public static unsafe partial class Log
{
    [DllImport("sokol", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
    public static extern void slog_func([NativeTypeName("const char *")] sbyte* tag, [NativeTypeName("uint32_t")] uint log_level, [NativeTypeName("uint32_t")] uint log_item, [NativeTypeName("const char *")] sbyte* message, [NativeTypeName("uint32_t")] uint line_nr, [NativeTypeName("const char *")] sbyte* filename, void* user_data);
}

I'm about to look at the code and see if I can find the bug real quick but logging it here as well just so it's surfaced

@kkukshtel
Copy link
Contributor Author

It seems like it has to be this line based on where GenerateFileScopedNamespaces is used and what is actually writing a }, but assuming that GenerateFileScopedNamespaces is declared something else seems like it's happening? Is the option not persisted across files or something?

if (_config.GenerateMultipleFiles && !Config.GenerateFileScopedNamespaces)

@tannergooding
Copy link
Member

This is probably an edge case missed for single-file mode.

Doing file-scoped-namespaces + single-file could already run into multiple potential issues (such as if different types need different namespaces) and so its not a common combination that develoeprs use.

@kkukshtel
Copy link
Contributor Author

@tannergooding could the linked line just case for that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants