Giter Club home page Giter Club logo

Comments (5)

kovidgoyal avatar kovidgoyal commented on July 3, 2024

So dont do that. Compiling something in order to detect the compiler is
a crazy approach. If you dont know what the compiler is, you cannot in
general compile anything. GCC making it impossible to detect what
compiler it is from its --version output, is a bug in gcc. That said
maybe I can instead check for clang since it seems to have a much more
sensible design than gcc.

from kitty.

ahesford avatar ahesford commented on July 3, 2024

On the contrary; the crazy approach is scraping version output that is clearly fragile and intended for human, not machine, consumption. The most sane way to tell if you can pass certain options to a compiler (without requiring up-front user input) is to try to run it with those arguments and find out if it complains.

Alternatively, exposing tunables to allow builders to indicate what compiler should be expected is a simple and reliable method to solve this problem.

from kitty.

kovidgoyal avatar kovidgoyal commented on July 3, 2024

Only GCC's --version output is fragile. And as I said that is a bug in GCC. One I will workaround by switching detection to check for clang. And incidentally passing flags to a compiler to check if itcomplains is bonkers. That only tells you whether the compiler runs or not. It does not distiguish between different compilers having different effects from the same flag. Many compilers implement flags from each other and ignore them in the name of some misguided attempt at being drop in replacements for each other.

from kitty.

kovidgoyal avatar kovidgoyal commented on July 3, 2024

Oh yeah and kitty's build system supports the CC env var just fine. So use that as your tuneable.

from kitty.

eli-schwartz avatar eli-schwartz commented on July 3, 2024

You don't need to compile anything to get the compiler ID.

Meson, for example, has a lot of very complex logic to detect many different compilers. It detects that cc.get_id() should be "gcc" by probing the --version output, it simply doesn't check for "gcc" as the first word: https://github.com/mesonbuild/meson/blob/0b7b4a3d9e41901b000074e903ad0bb8a299785c/mesonbuild/compilers/detect.py#L339

Instead, it checks for "Free Software Foundation" in the output.

Well, actually it uses that to detect "gcc_or_lcc". In case you care about the lcc compiler, it does then check for compiler defines via $CC -E -dM - < /dev/null, still no compilation needed.

There are other interesting things going on there -- the file is 1400 lines long, and quite a bit of it is just for detecting C / C++ compilers specifically. It's not as simple a task as people might assume.

(This is why eventually people trend towards migrating to dedicated build systems.)

from kitty.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.