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 "dumpmachine"/"dumpmachinefull" arguments to get the target machine triplet ("dumpmachinefull" for the full MSVC version). #14

Closed
wants to merge 0 commits into from

Conversation

falhumai96
Copy link

Add two new command-line arguments to get the target machine's triplet, by parsing the command-line output of cl:
* dumpmachine, which is to get the base machine triplet in the format {arch}-pc-windows-msvc, where {arch} is the target archetecture. If the target architecture is ARM or X86, {arch} will be set to armv7 or i386, respectfully (since there are many ARM or X86 archetectures). dumpmachine is similer to that of gcc/clang's command of the same name.
* dumpmachinefull, which has the same output as dumpmachine, except it is post-fixed by the full MSVC version being used. In other words, the command-line argument has the following format {arch}-pc-windows-msvc{msvcver}, where {arch} is the target archetecture and {msvcver} is the MSVC version.

These arguments precede any other arguments passed to cccl, and if dumpmachine/dumpmachinefull is processed, it will print the target triplet and exit succefully (the first of dumpmachine or dumpmachinefull will be processed).

Copy link
Member

@vadz vadz left a comment

Choose a reason for hiding this comment

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

Thanks for the addition, this looks useful, but I just wanted to point out a couple of possible (minor) improvements.

cccl Outdated
@@ -39,6 +39,30 @@ case $MACHTYPE in
;;
esac

for arg in $@; do
if [ "$arg" == "-dumpmachine" ] || [ "$arg" == "-dumpmachinefull" ]; then
Copy link
Member

Choose a reason for hiding this comment

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

I don't know why, but this script uses if test in all the other places, so it should probably be used here too for consistency? Personally, I'd use if [[ ... ]] in a bash script, e.g.

Suggested change
if [ "$arg" == "-dumpmachine" ] || [ "$arg" == "-dumpmachinefull" ]; then
if [[ $arg =~ ^-dumpmachine(full)?$ ]]; then

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for the suggestion. I will fix it to make it go along with other parts of the code as well.

Copy link
Member

Choose a reason for hiding this comment

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

I prefer the original, much simpler and easier to follow and probably more portable and possibly more portable if using =. @vadz is right, we do use if test everywhere, I think because we originally used sh instead of bash. Anyway, I'm no bash expert and don't really understand portability subtleties in bash except that what we currently using is meant to be more portable. Anyway, happy to be defer to some bash experts here.

cccl Outdated
fi
arch="$(echo ${cmd_out_parts[8]} | awk '{print tolower($0)}')"
output="pc-windows-$msvc"
if [ "$arch" = "x64" ]; then
Copy link
Member

Choose a reason for hiding this comment

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

This should be a case IMHO, for consistency with the similar code above and below and also because it seems better to use a single case rather than a chain of if/elif.

Copy link
Author

Choose a reason for hiding this comment

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

I will switch to case instead.

cccl Outdated
if [ "$arch" = "x64" ]; then
output="x86_64-$output"
elif [ "$arch" = "x86" ]; then
output="i386-$output"
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if it should be i386 or i686. It seems clang uses the former, Rust uses the latter.

Copy link
Author

Choose a reason for hiding this comment

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

When I create an X86 file, the file command, which calls libmagic, shows that it is an Intel 80386, which is i386. Not sure how accurate that is, but this is why I went with i386. I also did the same with armv7.

Copy link
Author

Choose a reason for hiding this comment

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

@vadz I have updated the code with the new changes based on your suggestions, as well as documented why I chose the above architectures in some code comments.

@wsfulton
Copy link
Member

wsfulton commented Mar 2, 2022

This patch needs documenting with the added options like all the other options are documented. Can you point me to some cc compiler that implements -dumpmachinefull?

@falhumai96
Copy link
Author

falhumai96 commented Mar 2, 2022

This patch needs documenting with the added options like all the other options are documented. Can you point me to some cc compiler that implements -dumpmachinefull?

I don't think there is a cc-like compiler frontend that has dumpmachinefull. I just added it to have more info on the MSVC version.

But, you are right. I need to add documentation to the code.

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.

3 participants