rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* help installing the correct version of bindgen
@ 2022-05-23 20:28 Nick Desaulniers
  2022-05-24 12:08 ` Miguel Ojeda
  0 siblings, 1 reply; 5+ messages in thread
From: Nick Desaulniers @ 2022-05-23 20:28 UTC (permalink / raw)
  To: rust-for-linux, Miguel Ojeda

Re: https://github.com/KyleMayes/clang-sys/issues/138

via the documentation patch
https://lore.kernel.org/lkml/20220523020209.11810-21-ojeda@kernel.org/

So after a defconfig, I see in my .config:
CONFIG_HAVE_RUST=y
but not
RUST_IS_AVAILABLE=y

$ make LLVM=1 -j72 rustavailable
make: *** [Makefile:1802: rustavailable] Error 1

$ cargo install --locked --version $(scripts/min-tool-version.sh
bindgen) bindgen
...
     Ignored package `bindgen v0.56.0` is already installed, use
--force to override

$ RUST_BACKTRACE=1 bindgen scripts/rust-is-available-bindgen-libclang.h
thread 'main' panicked at 'called `Result::unwrap()` on an `Err`
value: "could not run executable `/android0/llvm-project/clang`:
Permission denied (os error 13)"',
/usr/local/google/home/ndesaulniers/.cargo/registry/src/github.com-1ecc6299db9ec823/clang-sys-1.0.3/src/support.rs:165:58
stack backtrace:
   0: rust_begin_unwind
             at
/rustc/7737e0b5c4103216d6fd8cf941b7ab9bdbaace7c/library/std/src/panicking.rs:584:5
   1: core::panicking::panic_fmt
             at
/rustc/7737e0b5c4103216d6fd8cf941b7ab9bdbaace7c/library/core/src/panicking.rs:143:14
   2: core::result::unwrap_failed
             at
/rustc/7737e0b5c4103216d6fd8cf941b7ab9bdbaace7c/library/core/src/result.rs:1749:5
   3: clang_sys::support::run_clang
   4: clang_sys::support::parse_version
   5: clang_sys::support::Clang::find
   6: bindgen::Builder::generate
   7: bindgen::main
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a
verbose backtrace.

So it looks like bindgen is using clang-sys-1.0.3?
And it's finding my source code checkout of clang from the llvm-project.

Looking at https://github.com/rust-lang/rust-bindgen/tree/11ae35089e4748b7e2a6f50f6bef7709af72e724
specifically
https://github.com/rust-lang/rust-bindgen/blob/11ae35089e4748b7e2a6f50f6bef7709af72e724/Cargo.toml#L52
it just says "use version 1". But the latest version of clang-sys is
1.3.2 according to https://crates.io/crates/clang-sys.

What gives?
-- 
Thanks,
~Nick Desaulniers

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

* Re: help installing the correct version of bindgen
  2022-05-23 20:28 help installing the correct version of bindgen Nick Desaulniers
@ 2022-05-24 12:08 ` Miguel Ojeda
  2022-05-24 22:28   ` Nick Desaulniers
  0 siblings, 1 reply; 5+ messages in thread
From: Miguel Ojeda @ 2022-05-24 12:08 UTC (permalink / raw)
  To: Nick Desaulniers; +Cc: rust-for-linux, Miguel Ojeda

On Mon, May 23, 2022 at 10:28 PM Nick Desaulniers
<ndesaulniers@google.com> wrote:
>
> $ make LLVM=1 -j72 rustavailable
> make: *** [Makefile:1802: rustavailable] Error 1

I think we could have a message about `bindgen` being broken here if
calling it completely fails.

> So it looks like bindgen is using clang-sys-1.0.3?
> And it's finding my source code checkout of clang from the llvm-project.
>
> Looking at https://github.com/rust-lang/rust-bindgen/tree/11ae35089e4748b7e2a6f50f6bef7709af72e724
> specifically
> https://github.com/rust-lang/rust-bindgen/blob/11ae35089e4748b7e2a6f50f6bef7709af72e724/Cargo.toml#L52
> it just says "use version 1". But the latest version of clang-sys is
> 1.3.2 according to https://crates.io/crates/clang-sys.
>
> What gives?

`cargo install --locked` respects the Cargo.lock file, which indeed says 1.0.3:

    https://github.com/rust-lang/rust-bindgen/blob/v0.56.0/Cargo.lock#L83

When you installed the latest bindgen as you mention in the issue,
then you should see 1.2.0 (if you used `--locked`):

    https://github.com/rust-lang/rust-bindgen/blob/v0.59.2/Cargo.lock#L80

Hopefully this clarifies things a bit...

> And it's finding my source code checkout of clang from the llvm-project.

Have you tried tweaking the paths with
https://github.com/KyleMayes/clang-sys#environment-variables?

For instance, try to point it to the real executable with
CLANG_PATH=/android0/llvm-project/llvm/build/bin/clang etc.

Cheers,
Miguel

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

* Re: help installing the correct version of bindgen
  2022-05-24 12:08 ` Miguel Ojeda
@ 2022-05-24 22:28   ` Nick Desaulniers
  2022-05-24 23:39     ` Miguel Ojeda
  0 siblings, 1 reply; 5+ messages in thread
From: Nick Desaulniers @ 2022-05-24 22:28 UTC (permalink / raw)
  To: Miguel Ojeda; +Cc: rust-for-linux, Miguel Ojeda

On Tue, May 24, 2022 at 5:08 AM Miguel Ojeda
<miguel.ojeda.sandonis@gmail.com> wrote:
>
> On Mon, May 23, 2022 at 10:28 PM Nick Desaulniers
> <ndesaulniers@google.com> wrote:
> >
> > $ make LLVM=1 -j72 rustavailable
> > make: *** [Makefile:1802: rustavailable] Error 1
>
> I think we could have a message about `bindgen` being broken here if
> calling it completely fails.

There is a little bit of error handling; for my issue most of the
error message gets swallowed as shown above.  With the below diff:

```
diff --git a/Makefile b/Makefile
index e1ca0ef1ac26..386fa6c9e462 100644
--- a/Makefile
+++ b/Makefile
@@ -1800,7 +1800,7 @@ $(DOC_TARGETS):
 # "Is Rust available?" target
 PHONY += rustavailable
 rustavailable:
-       $(Q)$(CONFIG_SHELL) $(srctree)/scripts/rust-is-available.sh -v
&& echo >&2 "Rust is available!"
+       $(Q)$(CONFIG_SHELL) $(srctree)/scripts/rust-is-available.sh -v
&& echo >&2 "Rust is available!" || echo -e >&2 "Rust is not
available, try manually running\n'BINDGEN=bindgen RUSTC=rustc
scripts/rust-is-available.sh'" && exit 1

 # Documentation target
 #
diff --git a/scripts/rust-is-available.sh b/scripts/rust-is-available.sh
index 6bd395167d0f..9b54886d10f9 100755
--- a/scripts/rust-is-available.sh
+++ b/scripts/rust-is-available.sh
@@ -99,6 +99,9 @@ if [ "$1" = -v ] && [
"$rust_bindings_generator_cversion" -gt "$rust_bindings_ge
        echo >&2 "***"
 fi

+# Check that bindgen works.
+LC_ALL=C "$BINDGEN" $(dirname
$0)/rust-is-available-bindgen-libclang.h >/dev/null
+
 # Check that the `libclang` used by the Rust bindings generator is suitable.
 bindgen_libclang_version=$( \
        LC_ALL=C "$BINDGEN" $(dirname
$0)/rust-is-available-bindgen-libclang.h 2>&1 >/dev/null \
```

I instead get a clearer picture of what's going wrong:
```
$ make LLVM=1 -j72 rustavailable
thread 'main' panicked at 'called `Result::unwrap()` on an `Err`
value: "could not run executable `/android0/llvm-project/clang`:
Permission denied (os error 13)"',
/usr/local/google/home/ndesaulniers/.cargo/registry/src/github.com-1ecc6299db9ec823/clang-sys-1.0.3/src/support.rs:165:58
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Rust is not available, try manually running
'BINDGEN=bindgen RUSTC=rustc scripts/rust-is-available.sh'
make: *** [Makefile:1803: rustavailable] Error 1
```
compare that with the initial output I pasted.

>
> > So it looks like bindgen is using clang-sys-1.0.3?
> > And it's finding my source code checkout of clang from the llvm-project.
> >
> > Looking at https://github.com/rust-lang/rust-bindgen/tree/11ae35089e4748b7e2a6f50f6bef7709af72e724
> > specifically
> > https://github.com/rust-lang/rust-bindgen/blob/11ae35089e4748b7e2a6f50f6bef7709af72e724/Cargo.toml#L52
> > it just says "use version 1". But the latest version of clang-sys is
> > 1.3.2 according to https://crates.io/crates/clang-sys.
> >
> > What gives?
>
> `cargo install --locked` respects the Cargo.lock file, which indeed says 1.0.3:
>
>     https://github.com/rust-lang/rust-bindgen/blob/v0.56.0/Cargo.lock#L83

Ah, the lock file has the specific version. Ok

>
> When you installed the latest bindgen as you mention in the issue,
> then you should see 1.2.0 (if you used `--locked`):
>
>     https://github.com/rust-lang/rust-bindgen/blob/v0.59.2/Cargo.lock#L80

If I apply:
```
diff --git a/scripts/min-tool-version.sh b/scripts/min-tool-version.sh
index f1e8358ec19a..64ba8f20de22 100755
--- a/scripts/min-tool-version.sh
+++ b/scripts/min-tool-version.sh
@@ -34,7 +34,7 @@ rustc)
        echo 1.60.0
        ;;
 bindgen)
-       echo 0.56.0
+       echo 0.59.2
        ;;
 *)
        echo "$1: unknown tool" >&2
```
then do
$ cargo install --locked --version $(scripts/min-tool-version.sh
bindgen) bindgen
...
    Replaced package `bindgen v0.56.0` with `bindgen v0.59.2`
(executable `bindgen`)

$ make LLVM=1 -j72 rustavailable
thread 'main' panicked at 'called `Result::unwrap()` on an `Err`
value: "could not run executable `/android0/llvm-project/clang`:
Permission denied (os error 13)"',
/usr/local/google/home/ndesaulniers/.cargo/registry/src/github.com-1ecc6299db9ec823/clang-sys-1.2.0/src/support.rs:202:58
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Rust is not available, try manually running
'BINDGEN=bindgen RUSTC=rustc scripts/rust-is-available.sh'
make: *** [Makefile:1803: rustavailable] Error 1

So it looks like the error is not fixed in 1.2.0 release of clang-sys.
Left more comments in
https://github.com/KyleMayes/clang-sys/issues/138.

>
> Hopefully this clarifies things a bit...
>
> > And it's finding my source code checkout of clang from the llvm-project.
>
> Have you tried tweaking the paths with
> https://github.com/KyleMayes/clang-sys#environment-variables?
>
> For instance, try to point it to the real executable with
> CLANG_PATH=/android0/llvm-project/llvm/build/bin/clang etc.

I'd like to find out why dependencies are borked first, before
resorting to env vars.

$ CLANG_PATH=$(which clang) make LLVM=1 -j72 rustavailable
./scripts/rust-is-available-bindgen-libclang.h:2:9: warning: clang
version 15.0.0 (git@github.com:llvm/llvm-project.git
28c9ba577295221a3206defc58cb940833d87205) [-W#pragma-messages], err:
false
Rust is available!

does seem to work though.

$ CLANG_PATH=$(which clang) make LLVM=1 -j72 -s
./scripts/rust-is-available-bindgen-libclang.h:2:9: warning: clang
version 15.0.0 (git@github.com:llvm/llvm-project.git
28c9ba577295221a3206defc58cb940833d87205) [-W#pragma-messages], err:
false
error[E0063]: missing field `uring_cmd` in initializer of
`bindings_raw::file_operations`
   --> rust/kernel/file.rs:468:47
    |
468 |     const VTABLE: bindings::file_operations = bindings::file_operations {
    |
^^^^^^^^^^^^^^^^^^^^^^^^^ missing `uring_cmd`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0063`.
make[1]: *** [rust/Makefile:396: rust/kernel.o] Error 1
make: *** [Makefile:1291: prepare] Error 2

better than nothing. :) (I just reapplied your series on top of
a6b450573b912316ad36262bfc70e7c3870c56d1)
-- 
Thanks,
~Nick Desaulniers

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

* Re: help installing the correct version of bindgen
  2022-05-24 22:28   ` Nick Desaulniers
@ 2022-05-24 23:39     ` Miguel Ojeda
  2022-05-25  0:30       ` Nick Desaulniers
  0 siblings, 1 reply; 5+ messages in thread
From: Miguel Ojeda @ 2022-05-24 23:39 UTC (permalink / raw)
  To: Nick Desaulniers; +Cc: rust-for-linux, Miguel Ojeda

On Wed, May 25, 2022 at 12:28 AM Nick Desaulniers
<ndesaulniers@google.com> wrote:
>
> There is a little bit of error handling; for my issue most of the
> error message gets swallowed as shown above.  With the below diff:

Yeah, that is what I meant by having a message, or as you did, just
call it and let it print its own error. Thanks!

> So it looks like the error is not fixed in 1.2.0 release of clang-sys.
> Left more comments in
> https://github.com/KyleMayes/clang-sys/issues/138.

Thanks for following it up.

> I'd like to find out why dependencies are borked first, before
> resorting to env vars.

Definitely, but I suggested because it is good to know that solves it
so that there is not something else going on.

> does seem to work though.

Great -- thanks for trying it.

> error[E0063]: missing field `uring_cmd` in initializer of
> `bindings_raw::file_operations`
> ...
> better than nothing. :) (I just reapplied your series on top of
> a6b450573b912316ad36262bfc70e7c3870c56d1)

Yeah, a few hours ago ee692a21e9bf ("fs,io_uring: add infrastructure
for uring-cmd") got merged, which added a field to `struct
file_operations` so we need changes on the Rust side too.

If you try on top of v5.18 it should work, or if you apply a diff like
(may be wrapped):

```diff
diff --git a/rust/kernel/file.rs b/rust/kernel/file.rs
index e1b3b324bb3d..4c6513702cfa 100644
--- a/rust/kernel/file.rs
+++ b/rust/kernel/file.rs
@@ -534,6 +534,7 @@ impl<A: OpenAdapter<T::OpenData>, T: Operations>
OperationsVtable<A, T> {
         } else {
             None
         },
+        uring_cmd: None,
         write_iter: if T::TO_USE.write_iter {
             Some(Self::write_iter_callback)
         } else {
```

Cheers,
Miguel

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

* Re: help installing the correct version of bindgen
  2022-05-24 23:39     ` Miguel Ojeda
@ 2022-05-25  0:30       ` Nick Desaulniers
  0 siblings, 0 replies; 5+ messages in thread
From: Nick Desaulniers @ 2022-05-25  0:30 UTC (permalink / raw)
  To: Miguel Ojeda; +Cc: rust-for-linux, Miguel Ojeda

On Tue, May 24, 2022 at 4:39 PM Miguel Ojeda
<miguel.ojeda.sandonis@gmail.com> wrote:
>
> On Wed, May 25, 2022 at 12:28 AM Nick Desaulniers
> <ndesaulniers@google.com> wrote:
> >
> > There is a little bit of error handling; for my issue most of the
> > error message gets swallowed as shown above.  With the below diff:
>
> Yeah, that is what I meant by having a message, or as you did, just
> call it and let it print its own error. Thanks!
>
> > So it looks like the error is not fixed in 1.2.0 release of clang-sys.
> > Left more comments in
> > https://github.com/KyleMayes/clang-sys/issues/138.
>
> Thanks for following it up.
>
> > I'd like to find out why dependencies are borked first, before
> > resorting to env vars.
>
> Definitely, but I suggested because it is good to know that solves it
> so that there is not something else going on.
>
> > does seem to work though.
>
> Great -- thanks for trying it.

Aha! I think I have a fix for it:
https://github.com/KyleMayes/clang-sys/pull/142


-- 
Thanks,
~Nick Desaulniers

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

end of thread, other threads:[~2022-05-25  0:31 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-23 20:28 help installing the correct version of bindgen Nick Desaulniers
2022-05-24 12:08 ` Miguel Ojeda
2022-05-24 22:28   ` Nick Desaulniers
2022-05-24 23:39     ` Miguel Ojeda
2022-05-25  0:30       ` Nick Desaulniers

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).