This makes it easier to use header files generated by widl without Windows headers. In particular, headers generated with --no-rpc-includes do not need rpc.h and rpcndr.h header files.
Signed-off-by: Józef Kucia jkucia@codeweavers.com ---
This change is mainly for vkd3d. Currently, we use an ugly hack to strip RPC includes from the generated header files.
Version 2: Rebased.
--- tools/widl/header.c | 13 ++++++++----- tools/widl/widl.c | 7 +++++++ tools/widl/widl.h | 1 + tools/widl/widl.man.in | 2 ++ 4 files changed, 18 insertions(+), 5 deletions(-)
diff --git a/tools/widl/header.c b/tools/widl/header.c index defc7f850371..212c20a90148 100644 --- a/tools/widl/header.c +++ b/tools/widl/header.c @@ -1784,12 +1784,15 @@ void write_header(const statement_list_t *stmts) } fprintf(header, "/*** Autogenerated by WIDL %s from %s - Do not edit ***/\n\n", PACKAGE_VERSION, input_name);
- fprintf(header, "#ifndef __REQUIRED_RPCNDR_H_VERSION__\n"); - fprintf(header, "#define __REQUIRED_RPCNDR_H_VERSION__ 475\n"); - fprintf(header, "#endif\n\n"); + if (!no_rpc_includes) { + fprintf(header, "#ifndef __REQUIRED_RPCNDR_H_VERSION__\n"); + fprintf(header, "#define __REQUIRED_RPCNDR_H_VERSION__ 475\n"); + fprintf(header, "#endif\n\n"); + + fprintf(header, "#include <rpc.h>\n" ); + fprintf(header, "#include <rpcndr.h>\n" ); + }
- fprintf(header, "#include <rpc.h>\n" ); - fprintf(header, "#include <rpcndr.h>\n" ); if (!for_each_serializable(stmts, NULL, serializable_exists)) fprintf(header, "#include <midles.h>\n" ); fprintf(header, "\n" ); diff --git a/tools/widl/widl.c b/tools/widl/widl.c index 8fe8e4c62584..96b9d79b94b9 100644 --- a/tools/widl/widl.c +++ b/tools/widl/widl.c @@ -59,6 +59,7 @@ static const char usage[] = " -I path Set include search dir to path (multiple -I allowed)\n" " --local-stubs=file Write empty stubs for call_as/local methods to file\n" " -m32, -m64 Set the target architecture (Win32 or Win64)\n" +" --no-rpc-includes Do not generate RPC includes in header files.\n" " -N Do not preprocess input\n" " --oldnames Use old naming conventions\n" " -o, --output=NAME Set the output file name\n" @@ -119,6 +120,7 @@ int do_server = 0; int do_regscript = 0; int do_idfile = 0; int do_dlldata = 0; +int no_rpc_includes = 0; static int no_preprocess = 0; int old_names = 0; int win32_packing = 8; @@ -167,6 +169,7 @@ enum { PREFIX_CLIENT_OPTION, PREFIX_SERVER_OPTION, PRINT_HELP, + NO_RPC_INCLUDES_OPTION, RT_NS_PREFIX, RT_OPTION, ROBUST_OPTION, @@ -185,6 +188,7 @@ static const struct option long_options[] = { { "dlldata-only", 0, NULL, DLLDATA_ONLY_OPTION }, { "help", 0, NULL, PRINT_HELP }, { "local-stubs", 1, NULL, LOCAL_STUBS_OPTION }, + { "no-rpc-includes", 0, NULL, NO_RPC_INCLUDES_OPTION }, { "ns_prefix", 0, NULL, RT_NS_PREFIX }, { "oldnames", 0, NULL, OLDNAMES_OPTION }, { "output", 0, NULL, 'o' }, @@ -611,6 +615,9 @@ int main(int argc,char *argv[]) case RT_OPTION: winrt_mode = 1; break; + case NO_RPC_INCLUDES_OPTION: + no_rpc_includes = 1; + break; case RT_NS_PREFIX: use_abi_namespace = 1; break; diff --git a/tools/widl/widl.h b/tools/widl/widl.h index 4f4252e3ea3a..4767602231ca 100644 --- a/tools/widl/widl.h +++ b/tools/widl/widl.h @@ -44,6 +44,7 @@ extern int do_server; extern int do_regscript; extern int do_idfile; extern int do_dlldata; +extern int no_rpc_includes; extern int old_names; extern int win32_packing; extern int win64_packing; diff --git a/tools/widl/widl.man.in b/tools/widl/widl.man.in index ec81488a0e8d..402d9ebfc22b 100644 --- a/tools/widl/widl.man.in +++ b/tools/widl/widl.man.in @@ -47,6 +47,8 @@ Force the target architecture to 32-bit or 64-bit. Generate header files. The default output filename is \fIinfile\fB.h\fR. .IP "\fB--oldnames\fR" Use old naming conventions. +.IP "\fB--no-rpc-headers\fR" +Do not generate RPC includes. .PP .B Type library options: .IP \fB-t\fR
Hi Józef,
On 11/15/18 4:36 PM, Józef Kucia wrote:
This makes it easier to use header files generated by widl without Windows headers. In particular, headers generated with --no-rpc-includes do not need rpc.h and rpcndr.h header files.
Signed-off-by: Józef Kucia jkucia@codeweavers.com
This change is mainly for vkd3d. Currently, we use an ugly hack to strip RPC includes from the generated header files.
Version 2: Rebased.
tools/widl/header.c | 13 ++++++++----- tools/widl/widl.c | 7 +++++++ tools/widl/widl.h | 1 + tools/widl/widl.man.in | 2 ++ 4 files changed, 18 insertions(+), 5 deletions(-)
diff --git a/tools/widl/header.c b/tools/widl/header.c index defc7f850371..212c20a90148 100644 --- a/tools/widl/header.c +++ b/tools/widl/header.c @@ -1784,12 +1784,15 @@ void write_header(const statement_list_t *stmts) } fprintf(header, "/*** Autogenerated by WIDL %s from %s - Do not edit ***/\n\n", PACKAGE_VERSION, input_name);
- fprintf(header, "#ifndef __REQUIRED_RPCNDR_H_VERSION__\n");
- fprintf(header, "#define __REQUIRED_RPCNDR_H_VERSION__ 475\n");
- fprintf(header, "#endif\n\n");
- if (!no_rpc_includes) {
- fprintf(header, "#ifndef __REQUIRED_RPCNDR_H_VERSION__\n");
- fprintf(header, "#define __REQUIRED_RPCNDR_H_VERSION__ 475\n");
- fprintf(header, "#endif\n\n");
- fprintf(header, "#include <rpc.h>\n" );
- fprintf(header, "#include <rpcndr.h>\n" );
- }
- fprintf(header, "#include <rpc.h>\n" );
- fprintf(header, "#include <rpcndr.h>\n" ); if (!for_each_serializable(stmts, NULL, serializable_exists)) fprintf(header, "#include <midles.h>\n" ); fprintf(header, "\n" );
It probably doesn't matter much in practice, but midles.h should probably be treated the same way as other RPC includes.
Also could we just guard RPC includes with #ifdef _WIN32 instead? This wouldn't need a new command line option and would just make all generated headers usable on non-windows builds (at least to the same extend as --no-rpc-includes does). You could then use identical header in Wine and vkd3d.
Jacek
Hi Jacek,
Thanks for your feedback.
On Thu, Nov 15, 2018 at 7:06 PM Jacek Caban jacek@codeweavers.com wrote:
Also could we just guard RPC includes with #ifdef _WIN32 instead? This wouldn't need a new command line option and would just make all generated headers usable on non-windows builds (at least to the same extend as --no-rpc-includes does). You could then use identical header in Wine and vkd3d.
#ifdef _WIN32 works for me, if that is acceptable change for all headers generated by widl.
However, note that Wine code isn't compiled with _WIN32. We might need to use e.g. #if defined(_WIN32) || defined(__WINESRC__).
Hi Józef,
On 11/16/18 12:16 PM, Józef Kucia wrote:
Hi Jacek,
Thanks for your feedback.
On Thu, Nov 15, 2018 at 7:06 PM Jacek Caban jacek@codeweavers.com wrote:
Also could we just guard RPC includes with #ifdef _WIN32 instead? This wouldn't need a new command line option and would just make all generated headers usable on non-windows builds (at least to the same extend as --no-rpc-includes does). You could then use identical header in Wine and vkd3d.
#ifdef _WIN32 works for me, if that is acceptable change for all headers generated by widl.
However, note that Wine code isn't compiled with _WIN32. We might need to use e.g. #if defined(_WIN32) || defined(__WINESRC__).
We don't really need to worry about Wine itself. Note that in majority cases those includes are useless as rpc.h and rpcndr.h are included in a different ways. Mostly, if COM_NO_WINDOWS_H is not used, it will be included from generated header -> ole2.h -> objbase.h. As a test, I just put those includes inside #if 0 and Wine built fine.
Thanks,
Jacek
On Fri, Nov 16, 2018 at 12:36 PM Jacek Caban jacek@codeweavers.com wrote:
We don't really need to worry about Wine itself. Note that in majority cases those includes are useless as rpc.h and rpcndr.h are included in a different ways. Mostly, if COM_NO_WINDOWS_H is not used, it will be included from generated header -> ole2.h -> objbase.h. As a test, I just put those includes inside #if 0 and Wine built fine.
Yes, but I wanted to also guard windows.h and ole2.h. It would be a more complete solution, and it would allow me to remove COM_NO_WINDOWS_H from vkd3d headers.
On 11/16/18 12:42 PM, Józef Kucia wrote:
On Fri, Nov 16, 2018 at 12:36 PM Jacek Caban jacek@codeweavers.com wrote:
We don't really need to worry about Wine itself. Note that in majority cases those includes are useless as rpc.h and rpcndr.h are included in a different ways. Mostly, if COM_NO_WINDOWS_H is not used, it will be included from generated header -> ole2.h -> objbase.h. As a test, I just put those includes inside #if 0 and Wine built fine.
Yes, but I wanted to also guard windows.h and ole2.h. It would be a more complete solution, and it would allow me to remove COM_NO_WINDOWS_H from vkd3d headers.
I see, that makes sense. I would slightly prefer to not place Wine internal things like __WINESRC__ in all generated headers if it's easy to avoid, but it might make sense to introduce it here.
As a matter of fact we had __WINESRC__ check in the past (although back then it was to prevent windows.h include):
https://source.winehq.org/git/wine.git/commitdiff/42e583f1f6b2c0c9f963251495...
Back then we simply didn't depend on those includes in Wine sources and included them explicitly in .c file whenever needed. In current situation, checking for _WIN32 but not __WINESRC__ in generated headers would have the same effect. It would require changing some Wine files to explicitly include windows.h and/or ole2.h, but it might not be too bad, I'm not sure.
Thanks,
Jacek