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

Add zig rc subcommand, a (cross-platform) drop-in replacement for rc.exe #17412

Merged
merged 1 commit into from
Oct 12, 2023

Conversation

squeek502
Copy link
Collaborator

@squeek502 squeek502 commented Oct 5, 2023

Uses resinator under-the-hood (see #17069)

Closes #9564


The cmdRc function basically works exactly the same as main.zig in standalone resinator, meaning it will have the same output that the standalone resinator does, e.g. warnings like this:

zig-rc-output

zig rc passes the win32-samples-rc-tests with perfect results (matching standalone resinator):

Found RC compiler: resinator
Found RC compiler: zig

Processed 485 .rc files

---------------------------
  resinator
---------------------------

485 .rc files processed without discrepancies
identical .res outputs:     460
expected compile errors:    25

---------------------------
  zig rc
---------------------------

485 .rc files processed without discrepancies
identical .res outputs:     460
expected compile errors:    25

---------------------------

Results when cross-compiling that same set of test files from Linux:

identical .res outputs:    199
different .res outputs:    29
unexpected compile errors: 232

These results are expected, since the failing .rc files rely on either Windows path separators, MSVC-specific include files, or case-insensitive paths. The "different .res outputs" are caused by minor differences in the MinGW headers vs the MSVC headers (things like strings in common.ver)


And here's the usage/help text:

> zig rc /?
Usage: zig rc [options] [--] <INPUT> [<OUTPUT>]

The sequence -- can be used to signify when to stop parsing options.
This is necessary when the input path begins with a forward slash.

Supported Win32 RC Options:
  /?, /h                  Print this help and exit.
  /v                      Verbose (print progress messages).
  /d <name>[=<value>]     Define a symbol (during preprocessing).
  /u <name>               Undefine a symbol (during preprocessing).
  /fo <value>             Specify output file path.
  /l <value>              Set default language using hexadecimal id (ex: 409).
  /ln <value>             Set default language using language name (ex: en-us).
  /i <value>              Add an include path.
  /x                      Ignore INCLUDE environment variable.
  /c <value>              Set default code page (ex: 65001).
  /w                      Warn on invalid code page in .rc (instead of error).
  /y                      Suppress warnings for duplicate control IDs.
  /n                      Null-terminate all strings in string tables.
  /sl <value>             Specify string literal length limit in percentage (1-100)
                          where 100 corresponds to a limit of 8192. If the /sl
                          option is not specified, the default limit is 4097.
  /p                      Only run the preprocessor and output a .rcpp file.

No-op Win32 RC Options:
  /nologo, /a, /r         Options that are recognized but do nothing.

Unsupported Win32 RC Options:
  /fm, /q, /g, /gn, /g1, /g2     Unsupported MUI-related options.
  /?c, /hc, /t, /tp:<prefix>,    Unsupported LCX/LCE-related options.
     /tn, /tm, /tc, /tw, /te,
                    /ti, /ta
  /z                             Unsupported font-substitution-related option.
  /s                             Unsupported HWB-related option.

Custom Options (resinator-specific):
  /:no-preprocess           Do not run the preprocessor.
  /:debug                   Output the preprocessed .rc file and the parsed AST.
  /:auto-includes <value>   Set the automatic include path detection behavior.
    any                     (default) Use MSVC if available, fall back to MinGW
    msvc                    Use MSVC include paths (must be present on the system)
    gnu                     Use MinGW include paths (requires Zig as the preprocessor)
    none                    Do not use any autodetected include paths

Note: For compatibility reasons, all custom options start with :

Comment on lines +304 to +305
} else if (mem.eql(u8, cmd, "rc")) {
return cmdRc(gpa, arena, args[1..]);
Copy link
Collaborator Author

@squeek502 squeek502 Oct 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note:

    } else if (build_options.only_core_functionality) {
        @panic("only a few subcommands are supported in a zig2.c build");
    }

above takes care of ensuring resinator is not included in the build when only_core_functionality is true.

@squeek502 squeek502 changed the title Add zig rc subcommand, a drop-in replacement for rc.exe Add zig rc subcommand, a (cross-platform) drop-in replacement for rc.exe Oct 6, 2023
@squeek502 squeek502 marked this pull request as ready for review October 6, 2023 00:25
squeek502 added a commit to squeek502/win32-samples-rc-tests that referenced this pull request Oct 10, 2023
@andrewrk
Copy link
Member

Nice work!

@andrewrk andrewrk merged commit 2769215 into ziglang:master Oct 12, 2023
squeek502 added a commit to squeek502/zig that referenced this pull request Oct 19, 2023
The INCLUDE variable being used during preprocessing was an accidental regression caused by ziglang#17412.

Closes ziglang#17585.
squeek502 added a commit to squeek502/zig that referenced this pull request Oct 19, 2023
The INCLUDE variable being used during `.rc` preprocessing was an accidental regression in ziglang#17412.
Closes ziglang#17585.

resinator changes:
source_mapping: Protect against NUL bytes in #line filenames
lex: Avoid recalculating column on every tab stop within string literals
Proper error handling for failing to open cwd instead of `catch unreachable`
Use platform-specific delimiter for INCLUDE env var parsing
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

Successfully merging this pull request may close these issues.

zig windres
2 participants