[PATCH] D100755: [llvm-rc] [3/4] Run clang to preprocess input files

Alexandre Ganea via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 20 08:40:51 PDT 2021


aganea added a comment.

In D100755#2701649 <https://reviews.llvm.org/D100755#2701649>, @mstorsjo wrote:

> In D100755#2701608 <https://reviews.llvm.org/D100755#2701608>, @aganea wrote:
>
>> Thanks for adding this Martin!
>>
>> I'd really like to see a simple test running from the Clang side as well! Like calling llvm-rc with a file that requires preprocessing:
>
> That sounds like a good idea, as there's indeed a gap in testing at that spot right now.
>
> What would be the most appropriate place under clang/test for it?

Maybe under clang\test\Preprocessor ?

>> ---
>>
>> Also just for reference purposes, I'm pasting the little script I'm currently using to replace rc.exe on Linux. I've put it in the same folder as clang-cl and llvm-rc and now I'm able to use the same cmd-line as for rc.exe (it goes through a temp file which isn't ideal):
>>
>>   diff --git a/llvm/tools/llvm-rc/rc.sh b/llvm/tools/llvm-rc/rc.sh
>>   new file mode 100755
>>   index 000000000000..4a16f020aad8
>>   --- /dev/null
>>   +++ b/llvm/tools/llvm-rc/rc.sh
>>   @@ -0,0 +1,34 @@
>>   +#!/bin/bash
>>   +
>>   +INCLUDES=
>>   +for flag in "$@" 
>>   +do
>>   +        if [[ $flag =~ /Fo(.+) ]] ;
>>   +	then
>>   +		OUTFILE=${BASH_REMATCH[1]}
>>   +		OUTFLAG=$flag
>>   +	fi
>>   +	if [[ $flag =~ .+\.rc ]] ;
>>   +	then
>>   +		RCFILE=$flag
>>   +		RCPATH=$(dirname "${flag}")
>>   +	fi
>>   +	if [[ $flag =~ /I ]] ;
>>   +	then
>>   +		INCLUDES="$INCLUDES $flag"
>>   +	fi
>>   +	if [[ $flag == /nologo ]] ;
>>   +	then
>>   +		NOLOGO=$flag
>>   +	fi
>>   +done
>>   +if [[ $* =~ (/l[[:space:]]0x[[:alnum:]]+) ]] ;
>>   +then
>>   +	LANGUAGE="${BASH_REMATCH[1]}"
>>   +fi
>>   +
>>   +SCRIPTPATH=$(dirname "$0")
>>   +
>>   +$SCRIPTPATH/clang-cl /E ${RCFILE} ${INCLUDES} -nostdinc -Wno-nonportable-include-path > "${OUTFILE}.i"
>>   +$SCRIPTPATH/llvm-rc "${OUTFILE}.i" ${OUTFLAG} ${LANGUAGE} ${NOLOGO} /I${RCPATH}
>>   +
>
> Can the same things be emulated with the plain `rc.exe` tool too? I guess `-nostdinc` maps to the `/X` option (i.e. ignoring the `INCLUDE` variable), but I'm not sure if there's an official way of passing arbitrary preprocessor args with rc.exe (as rc.exe doesn't launch an out of process preprocessor, but it uses a built-in one). (With the windres interface, there's `--preprocessor-arg` though.)

`/X` is not exactly like `-nostdinc`, at least in Clang. `-nostdinc` has precedence over everything and it seemed the simplest way to be completly hermetic: https://github.com/llvm/llvm-project/blob/d480f968ad8b56d3ee4a6b6df5532d485b0ad01e/clang/lib/Driver/ToolChains/MSVC.cpp#L1234
(but we need to use `/clang:-isystem` instead of `-imsvc` for system headers)

As for the behavior of `rc.exe` on Windows, we start with clean env.vars and launch vcvars64.bat from the nuget package and that solves it. But on Linux we can't really do that. I agree, a new option `--preprocessor-arg` could help there?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D100755/new/

https://reviews.llvm.org/D100755



More information about the llvm-commits mailing list