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

Support for build scripts where host and target architecture match #97

Closed
allsey87 opened this issue Mar 8, 2021 · 17 comments
Closed

Comments

@allsey87
Copy link

allsey87 commented Mar 8, 2021

Is it the case at the moment, that any package using a build script will not compile?

With an empty project, it seems that as soon as I add a dependency on a package that includes a build.rs, the build fails. For example, if I add log as a dependency, I get the output:

 DEBUG: Executing shell function do_compile
 NOTE: which rustc: /home/mallwright/poky/build/tmp/work/corei7-64-poky-linux/hello-rust/1.0.0-r0/recipe-sysroot-native/usr/bin/rustc
 NOTE: rustc --version rustc 1.49.0 (e1884a8e3 2020-12-29)
 NOTE: which cargo: /home/mallwright/poky/build/tmp/work/corei7-64-poky-linux/hello-rust/1.0.0-r0/recipe-sysroot-native/usr/bin/cargo
 NOTE: cargo --version cargo 1.49.0 (d00d64df9 2020-12-05)
 NOTE: cargo build --verbose --manifest-path /home/mallwright/poky/build/tmp/work/corei7-64-poky-linux/hello-rust/1.0.0-r0/Cargo.toml --target=x86_64-unknown-linux-gnu --release
     Updating crates.io index
  Downloading crates ...
   Downloaded log v0.4.14
   Downloaded cfg-if v1.0.0
    Compiling log v0.4.14
    Compiling cfg-if v1.0.0
      Running `rustc --crate-name build_script_build /home/mallwright/poky/build/tmp/work/corei7-64-poky-linux/hello-rust/1.0.0-r0/cargo_home/registry/src/github.51.al-1ecc6299db9ec823/log-0.4.14/build.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debuginfo=2 -C debug-assertions=off -C metadata=72f27afcef2156d3 -C extra-filename=-72f27afcef2156d3 --out-dir /home/mallwright/poky/build/tmp/work/corei7-64-poky-linux/hello-rust/1.0.0-r0/target/release/build/log-72f27afcef2156d3 -C linker=/home/mallwright/poky/build/tmp/work/corei7-64-poky-linux/hello-rust/1.0.0-r0/wrappers/linker-wrapper.sh -L dependency=/home/mallwright/poky/build/tmp/work/corei7-64-poky-linux/hello-rust/1.0.0-r0/target/release/deps --cap-lints allow`
      Running `rustc --crate-name cfg_if --edition=2018 /home/mallwright/poky/build/tmp/work/corei7-64-poky-linux/hello-rust/1.0.0-r0/cargo_home/registry/src/github.51.al-1ecc6299db9ec823/cfg-if-1.0.0/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -C embed-bitcode=no -C debuginfo=2 -C metadata=bb222c302d676c2e -C extra-filename=-bb222c302d676c2e --out-dir /home/mallwright/poky/build/tmp/work/corei7-64-poky-linux/hello-rust/1.0.0-r0/target/x86_64-unknown-linux-gnu/release/deps --target x86_64-unknown-linux-gnu -C linker=/home/mallwright/poky/build/tmp/work/corei7-64-poky-linux/hello-rust/1.0.0-r0/wrappers/linker-wrapper.sh -L dependency=/home/mallwright/poky/build/tmp/work/corei7-64-poky-linux/hello-rust/1.0.0-r0/target/x86_64-unknown-linux-gnu/release/deps -L dependency=/home/mallwright/poky/build/tmp/work/corei7-64-poky-linux/hello-rust/1.0.0-r0/target/release/deps --cap-lints allow`
      Running `/home/mallwright/poky/build/tmp/work/corei7-64-poky-linux/hello-rust/1.0.0-r0/target/release/build/log-72f27afcef2156d3/build-script-build`
 error: failed to run custom build command for `log v0.4.14`
 
 Caused by:
   could not execute process `/home/mallwright/poky/build/tmp/work/corei7-64-poky-linux/hello-rust/1.0.0-r0/target/release/build/log-72f27afcef2156d3/build-script-build` (never executed)
 
 Caused by:
   No such file or directory (os error 2)
 WARNING: exit code 101 from a shell command.
 ERROR: Execution of '/home/mallwright/poky/build/tmp/work/corei7-64-poky-linux/hello-rust/1.0.0-r0/temp/run.do_compile.61272' failed with exit code 101:
     Updating crates.io index
  Downloading crates ...
   Downloaded log v0.4.14
   Downloaded cfg-if v1.0.0
    Compiling log v0.4.14
    Compiling cfg-if v1.0.0
      Running `rustc --crate-name build_script_build /home/mallwright/poky/build/tmp/work/corei7-64-poky-linux/hello-rust/1.0.0-r0/cargo_home/registry/src/github.51.al-1ecc6299db9ec823/log-0.4.14/build.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debuginfo=2 -C debug-assertions=off -C metadata=72f27afcef2156d3 -C extra-filename=-72f27afcef2156d3 --out-dir /home/mallwright/poky/build/tmp/work/corei7-64-poky-linux/hello-rust/1.0.0-r0/target/release/build/log-72f27afcef2156d3 -C linker=/home/mallwright/poky/build/tmp/work/corei7-64-poky-linux/hello-rust/1.0.0-r0/wrappers/linker-wrapper.sh -L dependency=/home/mallwright/poky/build/tmp/work/corei7-64-poky-linux/hello-rust/1.0.0-r0/target/release/deps --cap-lints allow`
      Running `rustc --crate-name cfg_if --edition=2018 /home/mallwright/poky/build/tmp/work/corei7-64-poky-linux/hello-rust/1.0.0-r0/cargo_home/registry/src/github.51.al-1ecc6299db9ec823/cfg-if-1.0.0/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -C embed-bitcode=no -C debuginfo=2 -C metadata=bb222c302d676c2e -C extra-filename=-bb222c302d676c2e --out-dir /home/mallwright/poky/build/tmp/work/corei7-64-poky-linux/hello-rust/1.0.0-r0/target/x86_64-unknown-linux-gnu/release/deps --target x86_64-unknown-linux-gnu -C linker=/home/mallwright/poky/build/tmp/work/corei7-64-poky-linux/hello-rust/1.0.0-r0/wrappers/linker-wrapper.sh -L dependency=/home/mallwright/poky/build/tmp/work/corei7-64-poky-linux/hello-rust/1.0.0-r0/target/x86_64-unknown-linux-gnu/release/deps -L dependency=/home/mallwright/poky/build/tmp/work/corei7-64-poky-linux/hello-rust/1.0.0-r0/target/release/deps --cap-lints allow`
      Running `/home/mallwright/poky/build/tmp/work/corei7-64-poky-linux/hello-rust/1.0.0-r0/target/release/build/log-72f27afcef2156d3/build-script-build`
 error: failed to run custom build command for `log v0.4.14`
 
 Caused by:
   could not execute process `/home/mallwright/poky/build/tmp/work/corei7-64-poky-linux/hello-rust/1.0.0-r0/target/release/build/log-72f27afcef2156d3/build-script-build` (never executed)
 
 Caused by:
   No such file or directory (os error 2)
 WARNING: exit code 101 from a shell command.

My Yocto build configuration is as follows:

Build Configuration:
BB_VERSION           = "1.44.0"
BUILD_SYS            = "x86_64-linux"
NATIVELSBSTRING      = "universal"
TARGET_SYS           = "x86_64-poky-linux"
MACHINE              = "up-core"
DISTRO               = "poky"
DISTRO_VERSION       = "3.0.4"
TUNE_FEATURES        = "m64 corei7"
TARGET_FPU           = ""
meta                 
meta-poky            
meta-yocto-bsp       = "zeus:d88d62c20d7d8da85f02edb170dae0280624ad7e"
meta-intel           = "zeus:d9942d4c3a710406b051852de7232db03c297f4e"
meta-drone           = "master:eeda22624de668adcfb60661c8ac69b7703fb5d1"
meta-rust-bin        = "master:f8e79ed922c765fca224b2318ab172e0b59f4a4d"
meta-oe              
meta-python          
meta-networking      
meta-filesystems     = "zeus:2b5dd1eb81cd08bc065bc76125f2856e9383e98b"
@allsey87
Copy link
Author

allsey87 commented Mar 8, 2021

What I find a bit strange about this error, however, is that it claims that /home/mallwright/poky/build/tmp/work/corei7-64-poky-linux/hello-rust/1.0.0-r0/target/release/build/log-72f27afcef2156d3/build-script-build could not be found. However it does exist and is executable:

ls -al /home/mallwright/poky/build/tmp/work/corei7-64-poky-linux/hello-rust/1.0.0-r0/target/release/build/log-72f27afcef2156d3/build-script-build
-rwxr-xr-x 2 mallwright mallwright 3269416 Mar  8 15:24 /home/mallwright/poky/build/tmp/work/corei7-64-poky-linux/hello-rust/1.0.0-r0/target/release/build/log-72f27afcef2156d3/build-script-build

@nastevens
Copy link
Member

This sounds similar to #94 - could you please double-check that you've updated to the latest master?

@allsey87
Copy link
Author

allsey87 commented Mar 8, 2021

Hi @nastevens, I am indeed on the latest master, you can confirm that from the yocto build configuration:

meta-rust-bin = "master:f8e79ed922c765fca224b2318ab172e0b59f4a4d"

Perhaps this is an issue with build host and target architecture being (almost) the same?

BUILD_SYS = "x86_64-linux"
TARGET_SYS = "x86_64-poky-linux"

@allsey87
Copy link
Author

allsey87 commented Mar 9, 2021

This is the output of ldd for the build script. I think this issue is related to #94 and #56, in particular I suspect that the loader as specified on the last line of the output of ldd: /lib/ld-linux-x86-64.so.2 => /lib64/ld-linux-x86-64.so.2 (0x00007fa2a21bc000) is incorrect and should instead be something closer to: /lib64/ld-linux-x86-64.so.2 (0x00007fbe48ca0000)

ldd /home/mallwright/poky/build/tmp/work/corei7-64-poky-linux/hello-rust/1.0.0-r0/target/release/build/log-72f27afcef2156d3/build-script-build
	linux-vdso.so.1 (0x00007fff20be0000)
	libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fa2a1fa4000)
	libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fa2a1d85000)
	libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fa2a1b81000)
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fa2a1790000)
	/lib/ld-linux-x86-64.so.2 => /lib64/ld-linux-x86-64.so.2 (0x00007fa2a21bc000)

@allsey87
Copy link
Author

allsey87 commented Mar 9, 2021

Digging in a bit deeper, I can confirm that RUST_TARGET and RUST_BUILD are both set to x86_64-unknown-linux-gnu. I am able to get the build to complete successfully by changing linker-wrapper.sh to linker-wrapper-native.sh, that is:

diff --git a/classes/cargo.bbclass b/classes/cargo.bbclass
index bcb2c05..9f62759 100644
--- a/classes/cargo.bbclass
+++ b/classes/cargo.bbclass
@@ -61,7 +61,7 @@ create_cargo_config() {
     else
         echo > ${CARGO_HOME}/config
         echo "[target.${RUST_TARGET}]" >> ${CARGO_HOME}/config
-        echo "linker = '${WRAPPER_DIR}/linker-wrapper.sh'" >> ${CARGO_HOME}/config
+        echo "linker = '${WRAPPER_DIR}/linker-native-wrapper.sh'" >> ${CARGO_HOME}/config
     fi
 
     echo >> ${CARGO_HOME}/config

Although I am skeptical as to whether the final binary will run on my target. I will test this now.

@allsey87
Copy link
Author

allsey87 commented Mar 9, 2021

Indeed, this doesn't work and reports file not found, which as I understand, means that the loader was not found.

root@up-core:~# which hello-rust
/usr/bin/hello-rust
root@up-core:~# ls -al `which hello-rust`
-rwxr-xr-x    1 root     root        280888 Mar  9 10:34 /usr/bin/hello-rust
root@up-core:~# hello-rust
-sh: /usr/bin/hello-rust: No such file or directory

The output of ldd (run on the host since I don't have ldd on the target) is as follows, which is almost identical to #56

ldd hello-rust
	linux-vdso.so.1 (0x00007fffbd8c7000)
	libgcc_s.so.1 => /usr/lib/libgcc_s.so.1 (0x00007fb5a591d000)
	librt.so.1 => /usr/lib/librt.so.1 (0x00007fb5a5912000)
	libpthread.so.0 => /usr/lib/libpthread.so.0 (0x00007fb5a58f1000)
	libdl.so.2 => /usr/lib/libdl.so.2 (0x00007fb5a58ea000)
	libc.so.6 => /usr/lib/libc.so.6 (0x00007fb5a571d000)
	/home/mallwright/poky/build/tmp/sysroots-uninative/x86_64-linux/lib/ld-linux-x86-64.so.2 => /usr/lib64/ld-linux-x86-64.so.2 (0x00007fb5a5bb7000)

@allsey87
Copy link
Author

allsey87 commented Mar 9, 2021

@nastevens as you mentioned in your comment, the change in 2c460c0 causes problems for build.rs in dependency crates.

@allsey87 allsey87 changed the title Support for build scripts Support for build scripts (where RUST_TARGET = RUST_BUILD) Mar 9, 2021
@allsey87 allsey87 changed the title Support for build scripts (where RUST_TARGET = RUST_BUILD) Support for build scripts where host and target architecture are the same Mar 9, 2021
@allsey87 allsey87 changed the title Support for build scripts where host and target architecture are the same Support for build scripts where host and target architecture match Mar 9, 2021
@otavio
Copy link
Contributor

otavio commented Mar 25, 2021

@allsey87 last time I looked at this, we got non-build-script crates working. It seems we are blocked on Rust itself not allowing to have individual target setups for the same target.

@allsey87
Copy link
Author

@otavio do you know if there been an issue opened for this on the Rust's/cargo's repo?

@otavio
Copy link
Contributor

otavio commented Mar 26, 2021

@allsey87 yes, I found it in the past but didn't find it now. Sorry.

@rich-g
Copy link

rich-g commented May 20, 2021

@allsey87 @otavio Seems like this might be the issue in question? rust-lang/cargo#3349.

@otavio
Copy link
Contributor

otavio commented May 20, 2021

@rich-g exactly. It has a patch under work to fix it.

@rich-g
Copy link

rich-g commented Jun 1, 2021

Looks like the right tooling is now (or will be shortly) in place in nightly: https://github.com/rust-lang/cargo/blob/master/src/doc/src/reference/unstable.md#host-config

@otavio
Copy link
Contributor

otavio commented Jun 1, 2021

Yes, however, I believe we cannot use it stable until it is release. Am I wrong?

@nastevens
Copy link
Member

Yes, however, I believe we cannot use it stable until it is release. Am I wrong?

You're correct for how things work at present. You can work around it as described in #101 but I wouldn't feel comfortable adding the changes more generally until this is stabilized. That said I'm definitely open to workarounds using current stable if anyone has any ideas.

@jameshilliard
Copy link

The fix is available as of rust 1.54.0 stable, you can enable it like this.

@posborne
Copy link
Member

Should be fixed with the merge of #146

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.

6 participants