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 `winres` as a resource compiler tool for `clang` and `gcc` #233

Closed
rivy opened this Issue Oct 16, 2018 · 6 comments

Comments

Projects
None yet
2 participants
@rivy
Contributor

rivy commented Oct 16, 2018

Both clang and gcc have a working windows resource compiler (windres), included, at least with the windows versions. Would it be possible to add support for it?

@waruqi

This comment has been minimized.

Member

waruqi commented Oct 16, 2018

I will consider it in the next release because I am planning to release a new version.

@waruqi waruqi added this to the v2.2.3 milestone Oct 16, 2018

@waruqi

This comment has been minimized.

Member

waruqi commented Oct 19, 2018

I have added support for windres in mingw platform. You can see the commit d8a85a3 and try it :

$ xmake f -p mingw [--sdk=/xxxx/mingwsdk/]
$ xmake

For example on my macos:

$ xmake f -p mingw --sdk=/usr/local/Cellar/mingw-w64//5.0.2_1 -a x86_64 -
c -v
$ xmake -v
[00%]: ccache compiling.release src/main.c
ccache x86_64-w64-mingw32-gcc -c -fvisibility=hidden -O3 -I/usr/local/Cellar/mingw-w64/5.0.2_1/include -m64 -o build/.objs/testrc/mingw/x86_64/release/src/main.c.o src/main.c
[50%]: ccache compiling.release src/xmake.rc
x86_64-w64-mingw32-windres -I/usr/local/Cellar/mingw-w64/5.0.2_1/include src/xmake.rc build/.objs/testrc/mingw/x86_64/release/src/xmake.rc.o
[100%]: linking.release testrc.exe
x86_64-w64-mingw32-g++ -o build/mingw/x86_64/release/testrc.exe build/.objs/testrc/mingw/x86_64/release/src/main.c.o build/.objs/testrc/mingw/x86_64/release/src/xmake.rc.o -s -fvisibility=hidden -L/usr/local/Cellar/mingw-w64/5.0.2_1/lib -m64
bu

@waruqi waruqi added the done label Oct 19, 2018

@rivy

This comment has been minimized.

Contributor

rivy commented Oct 19, 2018

I don't have a MinGW setup right now. But, with clang and gcc installed, these two commands seem to be compiling correctly:

clang

C:>set CC=clang
C:>:: note: `clang` compile is using the MSVC `rc` compiler here (which appears to be compatible)
C:>xmake f -a x64 --cc=%CC% --cxx=%CC% --ld=%CC% --cflags=-m64 --ldflags=-m64 && xmake -v
checking for the Microsoft Visual Studio (x64) version ... 2017
configure
{
    arch = x64
,   ld = clang
,   ldflags = -m64
,   cxx = clang
,   ccache = true
,   clean = true
,   plat = windows
,   cc = clang
,   mode = release
,   kind = static
,   buildir = build
,   vs = 2017
,   host = windows
,   cflags = -m64
}

building to: build\windows.release.clang.x64\bin\hello.exe
checking for the rc.exe ... ok
checking for the resource compiler (mrc) ... rc.exe
checking for the ccache ... no
[00%]: compiling.release src\main.rc
rc.exe -Fobuild\\windows.release.clang.x64\\obj\\windows\\x64\\release\\src\\main.rc.obj src\\main.rc
Microsoft (R) Windows (R) Resource Compiler Version 10.0.10011.16384
Copyright (C) Microsoft Corporation.  All rights reserved.
checking for the clang ... ok
checking for the flags(clang) -O3 ... ok
[50%]: compiling.release src\main.c
clang -c -m64 -fvisibility=hidden -O3 -Qunused-arguments -o build\\windows.release.clang.x64\\obj\\windows\\x64\\release\\src\\main.c.obj src\\main.c
checking for the flags(clang) -E -MM ... ok
[100%]: linking.release hello.exe
clang -o build\\windows.release.clang.x64\\bin\\hello.exe build\\windows.release.clang.x64\\obj\\windows\\x64\\release\\src\\main.rc.obj build\\windows.release.clang.x64\\obj\\windows\\x64\\release\\src\\main.c.obj -m64 -s -fvisibility=hidden

gcc with --mrc=windres

C:>set CC=gcc
C:>xmake f -a x86 --cc=%CC% --cxx=%CC% --ld=%CC% --mrc=windres && xmake -v
checking for the Microsoft Visual Studio (x86) version ... 2017
configure
{
    arch = x86
,   ld = gcc
,   ccache = true
,   cxx = gcc
,   clean = true
,   plat = windows
,   mode = release
,   host = windows
,   kind = static
,   buildir = build
,   vs = 2017
,   mrc = windres
,   cc = gcc
}

building to: build\windows.release.gcc.x86\bin\hello.exe
checking for the ccache ... no
[00%]: compiling.release src\main.rc
windres src\\main.rc build\\windows.release.gcc.x86\\obj\\windows\\x86\\release\\src\\main.rc.obj
checking for the gcc ... ok
checking for the flags(gcc) -O3 ... ok
[100%]: linking.release hello.exe
gcc -o build\\windows.release.gcc.x86\\bin\\hello.exe build\\windows.release.gcc.x86\\obj\\windows\\x86\\release\\src\\main.rc.obj build\\windows.release.gcc.x86\\obj\\windows\\x86\\release\\src\\main.c.obj -s -fvisibility=hidden

Notably...

gcc with default resource compiler (which defaults to MSVC/VS rc) breaks (as expected?)

C:>set CC=gcc
C:>xmake f -a x86 --cc=%CC% --cxx=%CC% --ld=%CC% && xmake -v
checking for the Microsoft Visual Studio (x86) version ... 2017
configure
{
    arch = x86
,   ld = gcc
,   host = windows
,   clean = true
,   plat = windows
,   ccache = true
,   mode = release
,   kind = static
,   buildir = build
,   vs = 2017
,   cc = gcc
,   cxx = gcc
}

building to: build\windows.release.gcc.x86\bin\hello.exe
checking for the rc.exe ... ok
checking for the resource compiler (mrc) ... rc.exe
checking for the ccache ... no
checking for the gcc ... ok
checking for the flags(gcc) -O3 ... ok
[100%]: linking.release hello.exe
gcc -o build\\windows.release.gcc.x86\\bin\\hello.exe build\\windows.release.gcc.x86\\obj\\windows\\x86\\release\\src\\main.rc.obj build\\windows.release.gcc.x86\\obj\\windows\\x86\\release\\src\\main.c.obj -s -fvisibility=hidden
error: build\windows.release.gcc.x86\obj\windows\x86\release\src\main.rc.obj: file not recognized: File format not recognized
collect2.exe: error: ld returned 1 exit status

And, the llvm-rc resource compiler included with clang still seems to be a work-in-progress (ref: mesonbuild/meson#4105 (comment)) and has errors when used:

clang with llvm-rc (broken, as expected as of 2018-10-19)

C:>set CC=clang
C:>xmake f -a x64 --cc=%CC% --cxx=%CC% --ld=%CC% --cflags=-m64 --ldflags=-m64 --mrc=llvm-rc && xmake -v
checking for the Microsoft Visual Studio (x64) version ... 2017
configure
{
    ccache = true
,   arch = x64
,   ld = clang
,   ldflags = -m64
,   cc = clang
,   cxx = clang
,   clean = true
,   plat = windows
,   host = windows
,   mode = release
,   kind = static
,   buildir = build
,   vs = 2017
,   mrc = llvm-rc
,   cflags = -m64
}

building to: build\windows.release.clang.x64\bin\hello.exe
checking for the ccache ... no
[00%]: compiling.release src\main.rc
llvm-rc -Fobuild\\windows.release.clang.x64\\obj\\windows\\x64\\release\\src\\main.rc.obj src\\main.rc
error: llvm-rc: Error parsing file: expected '-', '~', integer or '(', got LANG_ENGLISH

Overall, a good usability improvement!

@waruqi

This comment has been minimized.

Member

waruqi commented Oct 19, 2018

I only supported windres now and I have not yet supported llvm-rc.

@waruqi

This comment has been minimized.

Member

waruqi commented Oct 20, 2018

@rivy

This comment has been minimized.

Contributor

rivy commented Nov 2, 2018

It's working from my testing on my machine.

The error during normal operation (even though just during verbose) was still bothering me, so I made a small change to move checks which have simple/non-function opt.check together with missing opt.check. This suppresses the error message when searching for "rc".

I made a PR with the change for your consideration (see #247).

@waruqi waruqi closed this Nov 2, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment