rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* How are rustc -Z flags enabled during build?
@ 2021-09-01 23:07 Daniel Xu
  2021-09-02  0:50 ` Gary Guo
  2021-09-02  5:50 ` Miguel Ojeda
  0 siblings, 2 replies; 4+ messages in thread
From: Daniel Xu @ 2021-09-01 23:07 UTC (permalink / raw)
  To: rust-for-linux

Hi,

Context: While hacking on some rust modules, I ran into a bug where
kbuild was trying to generate BTF (from DWARF) for rust kernel modules.
I'm guessing one cannot generate valid BTF from rust debuginfo b/c at
module load time the btf parser complains and errors out the module
load. I know how to fix this and am planning on sending a fix.

In trying to fix the BTF issue, I'm trying to get more familiar w/
kbuild. Specifically, I've run `make V=1 LLVM=1 -j32` to try and figure
out exactly where the .o's are being created. I see the following
command:

    RUST_MODFILE=samples/rust/rust_minimal rustc
    --emit=dep-info,obj,metadata --edition=2018 -Cpanic=abort
    -Cembed-bitcode=n -Clto=n -Crpath=n -Cforce-unwind-tables=n
    -Ccodegen-units=1 -Zbinary_dep_depinfo=y
    -Zsymbol-mangling-version=v0 -Dunsafe_op_in_unsafe_fn
    -Drust_2018_idioms -Wmissing_docs -Cdebug-assertions=y
    -Coverflow-checks=y -Copt-level=2 -Cdebuginfo=2 --cfg MODULE
    @./include/generated/rustc_cfg
    --target=/home/dxu/dev/linux/arch/x86/rust/target.json
    -Zallow-features=allocator_api,bench_black_box,concat_idents,global_asm,try_reserve
    --extern alloc --extern kernel --crate-type rlib --out-dir /tmp/rust
    -L ./rust/ --crate-name rust_minimal samples/rust/rust_minimal.rs

When I try to run it outside of kbuild, I get:

    error: the option `Z` is only accepted on the nightly compiler

How does kbuild use the -Z features on a stable rustc?


Thanks,
Daniel

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: How are rustc -Z flags enabled during build?
  2021-09-01 23:07 How are rustc -Z flags enabled during build? Daniel Xu
@ 2021-09-02  0:50 ` Gary Guo
  2021-09-02  5:50 ` Miguel Ojeda
  1 sibling, 0 replies; 4+ messages in thread
From: Gary Guo @ 2021-09-02  0:50 UTC (permalink / raw)
  To: Daniel Xu; +Cc: rust-for-linux

On Wed, 1 Sep 2021 16:07:15 -0700
Daniel Xu <dxu@dxuuu.xyz> wrote:

> 
> When I try to run it outside of kbuild, I get:
> 
>     error: the option `Z` is only accepted on the nightly compiler
> 
> How does kbuild use the -Z features on a stable rustc?
> 

You can set environment variable `RUSTC_BOOTSTRAP=1`.

- Gary Guo

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: How are rustc -Z flags enabled during build?
  2021-09-01 23:07 How are rustc -Z flags enabled during build? Daniel Xu
  2021-09-02  0:50 ` Gary Guo
@ 2021-09-02  5:50 ` Miguel Ojeda
  2021-09-02 18:41   ` Daniel Xu
  1 sibling, 1 reply; 4+ messages in thread
From: Miguel Ojeda @ 2021-09-02  5:50 UTC (permalink / raw)
  To: Daniel Xu; +Cc: rust-for-linux

Hi Daniel,

On Thu, Sep 2, 2021 at 1:11 AM Daniel Xu <dxu@dxuuu.xyz> wrote:
>
> When I try to run it outside of kbuild, I get:
>
>     error: the option `Z` is only accepted on the nightly compiler
>
> How does kbuild use the -Z features on a stable rustc?

As Gary points out, it is an environment variable being set in the
top-level `Makefile` nearby the other flags. I considered adding it to
the command-line instead so that copy-pasting the lines is easier,
even if it means being a bit more verbose.

In any case, note that it is an escape hatch intended to be internal
to the compiler (which explains the error message not mentioning it)
and thus should be avoided unless a project has very special
constraints.

Our goal is to drop its usage as soon as it is feasible, but it will
take a while. It is also why we only maintain support for a given
`rustc` version for the moment.

Cheers,
Miguel

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: How are rustc -Z flags enabled during build?
  2021-09-02  5:50 ` Miguel Ojeda
@ 2021-09-02 18:41   ` Daniel Xu
  0 siblings, 0 replies; 4+ messages in thread
From: Daniel Xu @ 2021-09-02 18:41 UTC (permalink / raw)
  To: Miguel Ojeda; +Cc: rust-for-linux

Hi Gary, Miguel,

On Thu, Sep 02, 2021 at 07:50:44AM +0200, Miguel Ojeda wrote:
> Hi Daniel,
> 
> On Thu, Sep 2, 2021 at 1:11 AM Daniel Xu <dxu@dxuuu.xyz> wrote:
> >
> > When I try to run it outside of kbuild, I get:
> >
> >     error: the option `Z` is only accepted on the nightly compiler
> >
> > How does kbuild use the -Z features on a stable rustc?
> 
> As Gary points out, it is an environment variable being set in the
> top-level `Makefile` nearby the other flags. I considered adding it to
> the command-line instead so that copy-pasting the lines is easier,
> even if it means being a bit more verbose.
> 
> In any case, note that it is an escape hatch intended to be internal
> to the compiler (which explains the error message not mentioning it)
> and thus should be avoided unless a project has very special
> constraints.
> 
> Our goal is to drop its usage as soon as it is feasible, but it will
> take a while. It is also why we only maintain support for a given
> `rustc` version for the moment.
> 
> Cheers,
> Miguel

Thanks! I knew there must've been some magic somewhere :) .

Daniel

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-09-02 18:41 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-01 23:07 How are rustc -Z flags enabled during build? Daniel Xu
2021-09-02  0:50 ` Gary Guo
2021-09-02  5:50 ` Miguel Ojeda
2021-09-02 18:41   ` Daniel Xu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).