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

No way to specify custom C and C++ compilers in configuration #13805

Closed
mstewartgallus opened this issue Apr 27, 2014 · 4 comments · Fixed by #13823
Closed

No way to specify custom C and C++ compilers in configuration #13805

mstewartgallus opened this issue Apr 27, 2014 · 4 comments · Fixed by #13823

Comments

@mstewartgallus
Copy link
Contributor

There doesn't seem to be a way to specify custom C and C++ compiler in configuration.
As a bonus, if this is done then the --enable-clang and --enable-ccache flags can be thrown away.

Context: I need this capability because my system build of GCC is only at 4.6 (I'm using one of those really old long term support distributions) and I want to specify my custom build of GCC 4.9 so I can build the version of LLVM packaged with Rust. Yes, I could hack around this but it's simplest if Rust gains options to override the compilers.

@pnkfelix
Copy link
Member

I thought if you have the CC and CXX environment variables set, it will use those compilers. I haven't checked closely recently; is the problem that we only support those environment variables during make itself, and not during the execution of the configure script?

Anyway, we should try to make sure that some functionality of this sort works. (Though I don't think it would be a release blocker.)

Also, I am not sure we would be able to remove --enable-ccache if we fixed this issue. In particular we have at least one ccache specific hack to avoid spurious warnings from clang on a ccache-miss; you can review some of those details by looking at PR #6805.

@alexcrichton
Copy link
Member

You can also modify your PATH to point to the relevant compiler. The linux snapshot bots have a system gcc of 4.6 and I installed a 4.7 toolchain on them in a nonstandard location, and they're all building with the 4.7 toolchain.

A sample of the ./configure output: http://buildbot.rust-lang.org/builders/nightly-linux/builds/53/steps/configure/logs/stdio

@mstewartgallus
Copy link
Contributor Author

@pnkfelix, yes the CC and CXX environment variables don't work for configuring. I did not know about the reason for the --enable-ccache option, thanks.

@alexcrichton, Okay I'll use the PATH workaround for now (although that means one has to specify the PATH while doing the make as well).

@pnkfelix
Copy link
Member

okay, so maybe one easy way to satisfy this would be to make the configure script respect the CC and CXX environment variables, if set.

pnkfelix added a commit to pnkfelix/rust that referenced this issue May 19, 2014
I mostly tried to remain backwards compatible with old invocations of
the `configure` script; if you do not want to use `CC` et al., you
should not have to; you can keep using `--enable-clang` and/or
`--enable-ccache`.

The overall intention is to capture the following precedences for
guessing the C compiler:

 1. Value of `CC` at make invocation time.
 2. Value of `CC` at configure invocation time.
 3. Compiler inferred at configure invocation time (`gcc` or `clang`).

The strategy is to check (at `configure` time) if each of the
environment variables is set, and if so, save its value in a
corresponding `CFG_` variable (e.g. `CFG_CC`).

Then, in the makefiles, if `CC` is not set but `CFG_CC` is, then we
use the `CFG_CC` setting as `CC`.

Fix rust-lang#13805.

----

Note that if you try to set the compiler to clang via the `CC` and
`CXX` environment variables, you will probably need to also set
`CXXFLAGS` to `--enable-libcpp` so that LLVM will be configured
properly.

----

The `configure` script does not infer the compiler setting if `CC` is
set; but if `--enable-clang` was passed, then it *does* still attempt
to validate that the clang version is compatible.

Supporting this required revising `CLANG_VERSION` check to be robust
in face of user-provided `CC` value.

In particular, on Travis, the `CC` is set to `gcc` and so the natural
thing to do is to attempt to use `gcc` as the compiler, but Travis is
also passing `--enable-clang` to configure.  So, what is the right
answer in the face of these contradictory requests?

One approach would be to have `--enable-clang` supersede the setting
for `CC` (and instead just call whatever we inferred for `CFG_CLANG`).
That sounds maximally inflexible to me (pnkfelix): a developer
requesting a `CC` value probably wants it respected, and should be
able to set it to something else; it is harder for that developer to
hack our configure script to change its inferred path to clang.

A second approach would be to blindly use the `CC` value but keep
going through the clang version check when `--enable-clang` is turned
on.  But on Travis (a Linux host), the `gcc` invocation won't print a
clang version, so we would not get past the CLANG_VERSION check in
that context.

A third approach would be to never run the CLANG_VERSION check if `CC`
is explicitly set.  That is not a terrible idea; but if the user uses
`CC` to pass in a path to some other version of clang that they want
to test, probably should still send that through the `CLANG_VERSION`
check.

So in the end I (pnkfelix) took a fourth approach: do the
CLANG_VERSION check if `CC` is unset *or* if `CC` is set to a string
ending with `clang`.  This way setting `CC` to things like
`path/to/clang` or `ccache clang` will still go through the
CLANG_VERSION check, while setting `CC` to `gcc` or some unknown
compiler will skip the CLANG_VERSION check (regardless of whether the
user passed --enable-clang to `configure`).

----

As a drive-by fix, the call that sets `CFG_CLANG_VERSION` was quoting
`"$CFG_CC"` in its invocation, but that does not play nicely with
someone who sets `$CFG_CC` to e.g. `ccache clang`, since you do not
want to intepret that whole string as a command.

(On the other hand, a path with spaces might need the quoted
invocation.  Not sure which one of these corner use-cases is more
important to support.)
pnkfelix added a commit to pnkfelix/rust that referenced this issue May 20, 2014
I mostly tried to remain backwards compatible with old invocations of
the `configure` script; if you do not want to use `CC` et al., you
should not have to; you can keep using `--enable-clang` and/or
`--enable-ccache`.

The overall intention is to capture the following precedences for
guessing the C compiler:

 1. Value of `CC` at make invocation time.
 2. Value of `CC` at configure invocation time.
 3. Compiler inferred at configure invocation time (`gcc` or `clang`).

The strategy is to check (at `configure` time) if each of the
environment variables is set, and if so, save its value in a
corresponding `CFG_` variable (e.g. `CFG_CC`).

Then, in the makefiles, if `CC` is not set but `CFG_CC` is, then we
use the `CFG_CC` setting as `CC`.

Also, I fold the potential user-provided `CFLAGS` and `CXXFLAGS`
values into all of the per-platform `CFLAGS` and `CXXFLAGS` settings.
(This was opposed to adding `$(CFLAGS)` in an ad-hoc manner to various
parts of the mk files.)

Fix rust-lang#13805.

----

Note that if you try to set the compiler to clang via the `CC` and
`CXX` environment variables, you will probably need to also set
`CXXFLAGS` to `--enable-libcpp` so that LLVM will be configured
properly.

----

Introduce CFG_USING_CLANG, which is distinguished from
CFG_ENABLE_CLANG because the former represents "we think we're using
clang, choose appropriate warning-control options" while the latter
represents "we asked configure (or the host required) that we attempt
to use clang, so check that we have an appropriate version of clang."

The main reason I added this is that I wanted to allow the user to
choose clang via setting the `CC` environment variable, but I did not
want that method of selection to get confused with the user passing
the `--enable-clang` option.

----

A digression: The `configure` script does not infer the compiler
setting if `CC` is set; but if `--enable-clang` was passed, then it
*does* still attempt to validate that the clang version is compatible.

Supporting this required revising `CLANG_VERSION` check to be robust
in face of user-provided `CC` value.

In particular, on Travis, the `CC` is set to `gcc` and so the natural
thing to do is to attempt to use `gcc` as the compiler, but Travis is
also passing `--enable-clang` to configure.  So, what is the right
answer in the face of these contradictory requests?

One approach would be to have `--enable-clang` supersede the setting
for `CC` (and instead just call whatever we inferred for `CFG_CLANG`).
That sounds maximally inflexible to me (pnkfelix): a developer
requesting a `CC` value probably wants it respected, and should be
able to set it to something else; it is harder for that developer to
hack our configure script to change its inferred path to clang.

A second approach would be to blindly use the `CC` value but keep
going through the clang version check when `--enable-clang` is turned
on.  But on Travis (a Linux host), the `gcc` invocation won't print a
clang version, so we would not get past the CLANG_VERSION check in
that context.

A third approach would be to never run the CLANG_VERSION check if `CC`
is explicitly set.  That is not a terrible idea; but if the user uses
`CC` to pass in a path to some other version of clang that they want
to test, probably should still send that through the `CLANG_VERSION`
check.

So in the end I (pnkfelix) took a fourth approach: do the
CLANG_VERSION check if `CC` is unset *or* if `CC` is set to a string
ending with `clang`.  This way setting `CC` to things like
`path/to/clang` or `ccache clang` will still go through the
CLANG_VERSION check, while setting `CC` to `gcc` or some unknown
compiler will skip the CLANG_VERSION check (regardless of whether the
user passed --enable-clang to `configure`).

----

Drive-by fixes:

* The call that sets `CFG_CLANG_VERSION` was quoting `"$CFG_CC"` in
  its invocation, but that does not play nicely with someone who sets
  `$CFG_CC` to e.g. `ccache clang`, since you do not want to intepret
  that whole string as a command.

  (On the other hand, a path with spaces might need the quoted
  invocation.  Not sure which one of these corner use-cases is more
  important to support.)

* Fix chk_cc error message to point user at `gcc` not `cc`.
bors added a commit that referenced this issue May 21, 2014
Make configure script respect (and save) values for `CC`, `CXX`, `CFLAGS` etc.

I mostly tried to remain backwards compatible with old invocations of
the `configure` script; if you do not want to use `CC` et al., you
should not have to; you can keep using `--enable-clang` and/or
`--enable-ccache`.

The overall intention is to capture the following precedences for
guessing the C compiler:

 1. Value of `CC` at `make` invocation time.
 2. Value of `CC` at `configure` invocation time.
 3. Compiler inferred at configure invocation time (`gcc` or `clang`).

The strategy is to check (at `configure` time) if each of the
environment variables is set, and if so, save its value in a
corresponding `CFG_` variable (e.g. `CFG_CC`).

The `configure` script also does not attempt to infer the compiler if
`CC` is set; but if `--enable-clang` was passed, then it *does* still
attempt to validate that the clang version is compatible.

Then, in the makefiles, if `CC` is not set but `CFG_CC` is, then we
use the `CFG_CC` setting as `CC`.

Fix #13805.
arcnmx pushed a commit to arcnmx/rust that referenced this issue Jan 9, 2023
Complete enum variants without parens when snippets are disabled

This handles the portion of rust-lang#13767 that bothered me, but I can try to work on the other parts we discussed if needed.
arcnmx pushed a commit to arcnmx/rust that referenced this issue Jan 9, 2023
this is the record literal version of rust-lang#13805, which handled the same issue for
tuple literals
arcnmx pushed a commit to arcnmx/rust that referenced this issue Jan 9, 2023
Complete record enum variants without parens when snippets are disabled

I didn't realize I only handled this for tuple variants in rust-lang#13805. This is the same change but for record variants.
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 a pull request may close this issue.

3 participants