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

rust: Initial commit - rust lang #13916

Closed
wants to merge 1 commit into from
Closed

Conversation

Grommish
Copy link
Contributor

RFC - Rust Language integration into OpenWrt build environment.

This is a first try and will need to be gone over, corrected, fixed, etc.. I'm opening it up to the public for assistance.

Signed-off-by: Donald Hoskins grommish@gmail.com

lang/rust/Makefile Outdated Show resolved Hide resolved
lang/rust/Makefile Outdated Show resolved Hide resolved
lang/rust/rustc-triple.mk Outdated Show resolved Hide resolved
@Grommish Grommish changed the title [rust] Initial commit - rust lang rust: Initial commit - rust lang Nov 14, 2020
lang/rust/rust_compile.mk Outdated Show resolved Hide resolved
Copy link
Member

@BKPepe BKPepe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just quick a look at this PR. It requires to have commit messages for patches, which you are adding,

lang/rust/Makefile Outdated Show resolved Hide resolved
lang/rust/Makefile Outdated Show resolved Hide resolved
lang/rust/Makefile Show resolved Hide resolved
@Grommish
Copy link
Contributor Author

Grommish commented Jan 11, 2021 via email

lang/rust/Config.in Outdated Show resolved Hide resolved
Comment on lines 93 to 95
config RUST_OPTIMIZE
bool "Build optimized rust code (--enable-optimize)"
default n
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this correspond to optimize = false in config.toml? Setting that to false isn't supported, turning it off by default seems like a bad idea.

https://github.com/rust-lang/rust/blob/9503ea19edbf01b9435e80e17d60ce1b88390116/config.toml.example#L332-L336

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are only a few things I set in the TOML via --set having to do with the build system. (https://github.com/openwrt/packages/pull/13916/files#diff-000828b821201f172a6a3c1b97c5a89fd38753d46e7b0c11e475b7e61a99a24cR49)

These simply add (or not) the -- flag indicated (--enable-optimize in this case) to the arguments passed to ./configure

Copy link

@jyn514 jyn514 Feb 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well right, but it seems strange to me to expose this flag at all when there are a bunch of others you've left out. A compiler with optimize=false is basically useless, it will take a half hour just to compile the standard library.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I copied the output from ./configure --help to generate the list. Which did I miss? As we've discussed, I'm totally open to suggestions. :)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I don't think you need to expose every option by hand, there's a whole ton of them:

> grep -E '^(#[^ ]|\[)' config.toml.example 
#profile = <none>
[llvm]
#download-ci-llvm = false
#skip-rebuild = false
#optimize = true
#thin-lto = false
#release-debuginfo = false
#assertions = false
#ccache = false
#ccache = "/path/to/ccache"
#version-check = true
#static-libstdcpp = false
#ninja = true
#targets = "AArch64;ARM;Hexagon;MSP430;Mips;NVPTX;PowerPC;RISCV;Sparc;SystemZ;WebAssembly;X86"
#experimental-targets = "AVR"
#link-jobs = 0
#link-shared = false
#version-suffix = "-rust-dev"
#clang-cl = '/path/to/clang-cl.exe'
#cflags = "-fextra-flag"
#cxxflags = "-fextra-flag"
#ldflags = "-Wl,extra-flag"
#use-libcxx = true
#use-linker = "lld"
#allow-old-toolchain = false
#polly = false
[build]
#doc-stage = 0
#build-stage = 1
#test-stage = 1
#dist-stage = 2
#install-stage = 2
#bench-stage = 2
#build = "x86_64-unknown-linux-gnu"
#host = ["x86_64-unknown-linux-gnu"]
#target = ["x86_64-unknown-linux-gnu"]
#build-dir = "build"
#cargo = "/path/to/bin/cargo"
#rustc = "/path/to/bin/rustc"
#rustfmt = "/path/to/bin/rustfmt"
#docs = true
#compiler-docs = false
#submodules = true
#fast-submodules = true
#gdb = "gdb"
#nodejs = "node"
#python = "python"
#locked-deps = false
#vendor = false
#full-bootstrap = false
#extended = false
#tools = ["cargo", "rls", "clippy", "rustfmt", "analysis", "src"]
#verbose = 0
#sanitizers = false
#profiler = false
#cargo-native-static = false
#low-priority = false
#configure-args = []
#local-rebuild = false
#print-step-timings = false
[install]
#prefix = "/usr/local"
#sysconfdir = "/etc"
#docdir = "share/doc/rust"
#bindir = "bin"
#libdir = "lib"
#mandir = "share/man"
#datadir = "share"
#infodir = "share/info"
#localstatedir = "/var/lib"
[rust]
#optimize = true
#debug = false
#download-rustc = false
#codegen-units = if incremental { 256 } else { 16 }
#codegen-units-std = 1
#debug-assertions = rust.debug (boolean)
#debug-assertions-std = rust.debug-assertions (boolean)
#debug-logging = rust.debug-assertions (boolean)
#debuginfo-level = 0
#debuginfo-level-rustc = 0
#debuginfo-level-std = 0
#debuginfo-level-tools = 0
#debuginfo-level-tests = 0
#run-dsymutil = false
#backtrace = true
#incremental = false
#parallel-compiler = false
#default-linker = "cc"
#channel = "dev"
#description = ""
#musl-root = "..."
#rpath = true
#verbose-tests = false
#optimize-tests = true
#codegen-tests = true
#ignore-git = true
#dist-src = false
#save-toolstates = "/path/to/toolstates.json"
#codegen-backends = ["llvm"]
#lld = false
#use-lld = false
#llvm-tools = false
#deny-warnings = true
#backtrace-on-ice = false
#verify-llvm-ir = false
#thin-lto-import-instr-limit = 100
#remap-debuginfo = false
#jemalloc = false
#test-compare-mode = false
#llvm-libunwind = 'no'
#control-flow-guard = false
#new-symbol-mangling = false
[target.x86_64-unknown-linux-gnu]
#cc = "cc"
#cxx = "c++"
#ar = "ar"
#ranlib = "ranlib"
#linker = "cc"
#llvm-config = "../path/to/llvm/root/bin/llvm-config"
#llvm-filecheck = "/path/to/FileCheck"
#android-ndk = "/path/to/ndk"
#sanitizers = false
#profiler = false
#crt-static = false
#musl-root = "..."
#musl-libdir = musl-root/lib
#wasi-root = "..."
#qemu-rootfs = "..."
[dist]
#sign-folder = "path/to/folder/to/sign"
#gpg-password-file = "path/to/gpg/password"
#upload-addr = "https://example.com/folder"
#src-tarball = true
#missing-tools = false
#compression-formats = ["gz", "xz"]

My point was that this option doesn't seem particularly useful to expose, and especially shouldn't be on by default.

Comment on lines 97 to 95
config RUST_OPTIMIZE_LLVM
bool "Build optimized LLVM (--enable-optimize-llvm)"
default n
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know what OpenWRT policies are for release vs debug builds, but the compiler is significantly slower without ThinLTO, you may want to consider turning it on by default.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then let's turn that on :D I was not going to set defaults for things I didn't know about unless I needed something to work and it didn't. This worked fine off by default, and I was waiting for those with more knowledge (ahem.. poke) to step in and tell me different :) I'll try it

Comment on lines 117 to 115
config RUST_FULL_BOOTSTRAP
bool "Full Bootstrap - Build three compilers instead of two (--enable-full-bootstrap)"
default y
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why enable this by default? It shouldn't be needed and it will make the build take half again as long. https://github.com/rust-lang/rust/blob/9503ea19edbf01b9435e80e17d60ce1b88390116/config.toml.example#L243-L248

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was my understanding that in order to get stage2 artifacts, the full bootstrap needed to happen (so it didn't stop at just stage0/1)? Remember, almost everyone using Rust-lang in an OpenWrt context will be cross-compiling and will need the stage2 artifacts that would be skipped without the full bootstrap. Did I misunderstand?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think x.py should automatically rebuild stage2 if it needs to for cross compiling. I would try that first to see if it works.

Also, I'm slightly confused why you would need 3 compilers in the first place, I would expect a stage 2 compiler to work fine. That's what's distributed by rustup.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

x.py only gets call ONCE, during the initial compile. After that, the installation binaries I create are stored in an archive that is used instead of touching the rust source at all (unless the rust package version changes in the OpenWrt upstream). This means I only run x.py a single time for an install..

-rw-r--r-- 1 grommish grommish 520960752 Feb 11 00:57 rust-1.49.0-x86_64-unknown-linux-gnu_mips64-openwrt-linux-musl-install.tar.xz

That is an example of my toolchain installation files (basically, a one-off version of rustup I guess?) that are built during the first compile. Subsequent runs, even on a make clean, sees that file, extracts it, runs the installs, and calls it a day.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems reasonable, but I'm not sure how it's relevant. This is specifically about the rustc-dev component, which gets compiled with x.py at the same time as everything else. If you remove rustc-dev I think this option won't even be used either way.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm testing removing the -dev options as we speak to see if it breaks anything.. then, if not, I'll test without the full bootstrap

lang/rust/patches/00-default_dynamic_linking.patch Outdated Show resolved Hide resolved
Comment on lines 6 to 19
+pub fn target() -> Target {
+ let mut base = super::linux_musl_base::opts();
+ base.cpu = "mips64r2".to_string();
+ base.features = "+mips64r2,+soft-float".to_string();
+ base.max_atomic_width = Some(64);
+ Target {
+ // LLVM doesn't recognize "muslabi64" yet.
+ llvm_target: "mips64-unknown-linux-musl".to_string(),
+ pointer_width: 64,
+ data_layout: "E-m:e-i8:8:32-i16:16:32-i64:64-n32:64-S128".to_string(),
+ arch: "mips64".to_string(),
+ options: TargetOptions { endian: "big".to_string(), mcount: "_mcount".to_string(), ..base },
+ }
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks useful to other distros too :) have you considered upstreaming it to rust-lang/rust?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see why not, although it's just the built-in triple renamed and defined with a soft-float since the dynlinking is handles in the MUSL define.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any progress with upstreaming patches which you have for mips64, aarch64, etc?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mips64-openwrt-linux-musl was upstream'ed and merged into rust-lang master back in February, 2022. It's the only actual hardware I have to test on, architect-wise.

As I continue with testing, or getting confirmation that the various tuples don't cause issues (armv5 still doesn't work, for example) and figuring out whether errors I see are because of OpenWrt build system, the tuple, the rust install, or the package itself (or some other interaction and/or combined situations). For example, I've had a request for the vaultwarden package. I was seeing errors, I reported errors, and in the end, it was because the ring crate (which is a common crypto crate from what I can tell) uses BoringSSL, and BoringSSL doesn't work for BigEndian archs (like mips64) sigh. So chasing errors to ensure stability is a long, drawn out process.

And, even when everything seems to work, the end product may or may not work as intended. I had issues with suricata6 in which it would build with soft-float flagged, enabled in the mips64-openwrt-linux-musl tuple, but was SIGSEV erroring when I attempted to run it. Turns out, OpenWrt for mips64 didn't enable MIPS soft-float emulation in the kernel.

So, if anyone wants to help me test an arch, verification can happen and I can upstream them. They are responsive enough.

define Host/Compile
cd $(HOST_BUILD_DIR) && \
RUST_BACKTRACE=full $(PYTHON) x.py --config ./config.toml dist cargo extended \
library/std llvm-tools miri rust-dev rustc-dev
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why rust-dev and rustc-dev? That's the LLVM dynamic library and libraries for using rustc_private; they shouldn't be needed unless you're using a custom rustc driver.

@Grommish
Copy link
Contributor Author

Hi @jyn514 ;)

Honestly, I did the rust thing because I needed it, not because I know how to use it. Most of the comments I received while doing this went from "why?" to "can't be done". The suggestions/comments you've made I am certainly willing to entertain, as I KNOW there are better ways to optimize this. I do know that it WORKS, as is, so further testing would be needed..

I can't even beg people to identify their triples so I can patch them in :D and I've been too lazy to build out targets I don't have just to build a rust toolchain. As you mentioned, the first time takes a while..

I'll work through these suggestions and see what/if anything breaks. Thanks for the nudge!

@Grommish
Copy link
Contributor Author

Grommish commented Feb 15, 2021 via email

@jyn514
Copy link

jyn514 commented Feb 15, 2021

I don't know what the purpose of the options are, I guess. What are people looking for when they customize builds? If it were me I would probably pick one set of options and use them for everyone, but I also have never maintained packages before 😆

@Grommish
Copy link
Contributor Author

Grommish commented Feb 15, 2021 via email

@Grommish
Copy link
Contributor Author

Updated PR to include mipsel-24kc

lang/rust/rustc-config.mk Outdated Show resolved Hide resolved
@wulfy23
Copy link
Contributor

wulfy23 commented Mar 23, 2021

compile tested for aarch64/rpi4 @ 3:23mins ( 2 core pentium )

-needed ccache ( host/apt )
-would be good to see some forking or similar optimisations
-runs un-needed download.pl call but not entirely a bad move in the longer term scheme of things ( potential precompiled bins down the track? ;) )

other than that pretty smooth... thanks for the hard work

@Grommish
Copy link
Contributor Author

compile tested for aarch64/rpi4 @ 3:23mins ( 2 core pentium )

-needed ccache ( host/apt )
-would be good to see some forking or similar optimisations
-runs un-needed download.pl call but not entirely a bad move in the longer term scheme of things ( potential precompiled bins down the track? ;) )

other than that pretty smooth... thanks for the hard work

I actually wanted to use the download.mk and it's hash functions to create/verify the binaries hashes prior to using them. I have, however, redone how the binaries are stored, so it means MUCH shorter compile times in the future, and a smaller footprint in dl/. In theory, the buildbot could generate the toolchains and dole them out, but I don't know if that should/would ever happen.

cccache is selectable in the settings, although I believe I also just set it for the builder if the build env ccache is set (https://github.com/openwrt/packages/pull/13916/files#diff-f2f5c684ef57dc9ef001c539fb9a97c8a66e2efe84b68985fa23b45f8f4a1dc4R30).

@Grommish
Copy link
Contributor Author

Update to the build logic. The package now breaks the install binaries into the Host and Target components. This reduces on-disk footprint by roughly 360Mb for every extra target toolchain. It also allows for faster toolchain building when the Host toolchain is already in place.

@predators46
Copy link
Contributor

finally llvm-rust rust rust_host can be created in openwrt 22.03.0.

Screenshot_2022-09-22_081929

@robotronnn
Copy link

Will there be a tutorial how to put this on my device?

@predators46
Copy link
Contributor

Will there be a tutorial how to put this on my device?

you must add the packages llvm-rustc rust and rustc_host when you build openwrt. and keep in mind that some packages are made for the host, not packages that can be installed on the device

@lucize
Copy link
Contributor

lucize commented Sep 29, 2022

don't understand how you guys can compile this, despite that there are errors in Makefile (fixable) like

Makefile:120: *** Package/rust_host is missing the TITLE field.  Stop.
Makefile:96: *** Package/llvm-project-rustc is missing the TITLE field.  Stop.

I also get this

configure: processing command line
configure:
configure: error: Option '--program-prefix=' is not recognized

can't seems to understand from where is this coming
--build=x86_64-pc-linux-gnu --program-prefix="" --program-suffix="" --prefix=/usr

@predators46
Copy link
Contributor

don't understand how you guys can compile this, despite that there are errors in Makefile (fixable) like

Makefile:120: *** Package/rust_host is missing the TITLE field.  Stop.
Makefile:96: *** Package/llvm-project-rustc is missing the TITLE field.  Stop.

I also get this

configure: processing command line
configure:
configure: error: Option '--program-prefix=' is not recognized

can't seems to understand from where is this coming --build=x86_64-pc-linux-gnu --program-prefix="" --program-suffix="" --prefix=/usr

I hope you use the makefile here
https://github.com/Itus-Shield/packages/tree/rust_host

I didn't get the error you found

@lucize
Copy link
Contributor

lucize commented Sep 29, 2022

I'm on Ubuntu 22.04.1
downloaded your files


ERROR: please fix package/feeds/packages/llvm-project-rustc/Makefile - see logs/package/feeds/packages/llvm-project-rustc/dump.txt for details
ERROR: please fix package/feeds/packages/rust_host/Makefile - see logs/package/feeds/packages/rust_host/dump.txt for details


[...]

touch /home/build/staging/build_dir/target-x86_64_musl/rust-1.64.0/.prepared_7f4a872e4632bc670b50d7f04d738180_6664517399ebbbc92a37c5bb081b5c53
rm -f /home/build/staging/build_dir/target-x86_64_musl/rust-1.64.0/.configured_*
rm -f /home/build/staging/staging_dir/target-x86_64_musl/stamp/.rust_installed
(cd /home/build/staging/build_dir/target-x86_64_musl/rust-1.64.0/./; if [ -x ./configure ]; then find /home/build/staging/build_dir/target-x86_64_musl/rust-1.64.0/ -name config.guess | xargs -r chmod u+w; find /home/build/staging/build_dir/target-x86_64_musl/rust-1.64.0/ -name config.guess | xargs -r -n1 cp --remove-destination /home/build/staging/scripts/config.guess; find /home/build/staging/build_dir/target-x86_64_musl/rust-1.64.0/ -name config.sub | xargs -r chmod u+w; find /home/build/staging/build_dir/target-x86_64_musl/rust-1.64.0/ -name config.sub | xargs -r -n1 cp --remove-destination /home/build/staging/scripts/config.sub; AR="x86_64-openwrt-linux-musl-gcc-ar" AS="x86_64-openwrt-linux-musl-gcc -c -Os -pipe -fno-caller-saves -fno-plt -fhonour-copts -Wno-error=unused-but-set-variable -Wno-error=unused-result -fmacro-prefix-map=/home/build/staging/build_dir/target-x86_64_musl/rust-1.64.0=rust-1.64.0 -Wformat -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=1 -Wl,-z,now -Wl,-z,relro" LD=x86_64-openwrt-linux-musl-ld NM="x86_64-openwrt-linux-musl-gcc-nm" CC="x86_64-openwrt-linux-musl-gcc" GCC="x86_64-openwrt-linux-musl-gcc" CXX="x86_64-openwrt-linux-musl-g++" RANLIB="x86_64-openwrt-linux-musl-gcc-ranlib" STRIP=x86_64-openwrt-linux-musl-strip OBJCOPY=x86_64-openwrt-linux-musl-objcopy OBJDUMP=x86_64-openwrt-linux-musl-objdump SIZE=x86_64-openwrt-linux-musl-size CFLAGS="-Os -pipe -fno-caller-saves -fno-plt -fhonour-copts -Wno-error=unused-but-set-variable -Wno-error=unused-result -fmacro-prefix-map=/home/build/staging/build_dir/target-x86_64_musl/rust-1.64.0=rust-1.64.0 -Wformat -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=1 -Wl,-z,now -Wl,-z,relro " CXXFLAGS="-Os -pipe -fno-caller-saves -fno-plt -fhonour-copts -Wno-error=unused-but-set-variable -Wno-error=unused-result -fmacro-prefix-map=/home/build/staging/build_dir/target-x86_64_musl/rust-1.64.0=rust-1.64.0 -Wformat -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=1 -Wl,-z,now -Wl,-z,relro " CPPFLAGS="-I/home/build/staging/staging_dir/toolchain-x86_64_gcc-11.3.0_musl/usr/include -I/home/build/staging/staging_dir/toolchain-x86_64_gcc-11.3.0_musl/include/fortify -I/home/build/staging/staging_dir/toolchain-x86_64_gcc-11.3.0_musl/include " LDFLAGS="-L/home/build/staging/staging_dir/toolchain-x86_64_gcc-11.3.0_musl/usr/lib -L/home/build/staging/staging_dir/toolchain-x86_64_gcc-11.3.0_musl/lib -znow -zrelro "   ./configure --target=x86_64-openwrt-linux --host=x86_64-openwrt-linux --build=x86_64-pc-linux-gnu --program-prefix="" --program-suffix="" --prefix=/usr --exec-prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --libexecdir=/usr/lib --sysconfdir=/etc --datadir=/usr/share --localstatedir=/var --mandir=/usr/man --infodir=/usr/info --disable-nls  ; fi; )
configure: processing command line
configure:
configure: error: Option '--program-prefix=' is not recognized
make[2]: *** [Makefile:128: /home/build/staging/build_dir/target-x86_64_musl/rust-1.64.0/.configured_68b329da9893e34099c7d8ad5cb9c940] Error 1
make[2]: Leaving directory '/home/build/staging/feeds/packages/lang/rust'
time: package/feeds/packages/rust/compile#1.31#1.49#2.84
    ERROR: package/feeds/packages/rust failed to build.
make[1]: *** [package/Makefile:116: package/feeds/packages/rust/compile] Error 1
make[1]: Leaving directory '/home/build/staging'
make: *** [/home/build/staging/include/toplevel.mk:231: package/rust/compile] Error 2

sha256sum

91b33f45ac46790cae91e350e21881020915766d78675fe8d83c8a9d01d0fde6 devel/llvm-project-rustc/Makefile
4237dd900a40d8f7e99f48656b1ad69816f4925cf1f0e4cfa3104f074c44da07 lang/rust/Makefile
9a6682b40582a547db844fee03dad1d11feb31ad2e4c7f420e988ee3c012e8d6 lang/rust_host/Makefile

@predators46
Copy link
Contributor

I'm on Ubuntu 22.04.1 downloaded your files


ERROR: please fix package/feeds/packages/llvm-project-rustc/Makefile - see logs/package/feeds/packages/llvm-project-rustc/dump.txt for details
ERROR: please fix package/feeds/packages/rust_host/Makefile - see logs/package/feeds/packages/rust_host/dump.txt for details


[...]

touch /home/build/staging/build_dir/target-x86_64_musl/rust-1.64.0/.prepared_7f4a872e4632bc670b50d7f04d738180_6664517399ebbbc92a37c5bb081b5c53
rm -f /home/build/staging/build_dir/target-x86_64_musl/rust-1.64.0/.configured_*
rm -f /home/build/staging/staging_dir/target-x86_64_musl/stamp/.rust_installed
(cd /home/build/staging/build_dir/target-x86_64_musl/rust-1.64.0/./; if [ -x ./configure ]; then find /home/build/staging/build_dir/target-x86_64_musl/rust-1.64.0/ -name config.guess | xargs -r chmod u+w; find /home/build/staging/build_dir/target-x86_64_musl/rust-1.64.0/ -name config.guess | xargs -r -n1 cp --remove-destination /home/build/staging/scripts/config.guess; find /home/build/staging/build_dir/target-x86_64_musl/rust-1.64.0/ -name config.sub | xargs -r chmod u+w; find /home/build/staging/build_dir/target-x86_64_musl/rust-1.64.0/ -name config.sub | xargs -r -n1 cp --remove-destination /home/build/staging/scripts/config.sub; AR="x86_64-openwrt-linux-musl-gcc-ar" AS="x86_64-openwrt-linux-musl-gcc -c -Os -pipe -fno-caller-saves -fno-plt -fhonour-copts -Wno-error=unused-but-set-variable -Wno-error=unused-result -fmacro-prefix-map=/home/build/staging/build_dir/target-x86_64_musl/rust-1.64.0=rust-1.64.0 -Wformat -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=1 -Wl,-z,now -Wl,-z,relro" LD=x86_64-openwrt-linux-musl-ld NM="x86_64-openwrt-linux-musl-gcc-nm" CC="x86_64-openwrt-linux-musl-gcc" GCC="x86_64-openwrt-linux-musl-gcc" CXX="x86_64-openwrt-linux-musl-g++" RANLIB="x86_64-openwrt-linux-musl-gcc-ranlib" STRIP=x86_64-openwrt-linux-musl-strip OBJCOPY=x86_64-openwrt-linux-musl-objcopy OBJDUMP=x86_64-openwrt-linux-musl-objdump SIZE=x86_64-openwrt-linux-musl-size CFLAGS="-Os -pipe -fno-caller-saves -fno-plt -fhonour-copts -Wno-error=unused-but-set-variable -Wno-error=unused-result -fmacro-prefix-map=/home/build/staging/build_dir/target-x86_64_musl/rust-1.64.0=rust-1.64.0 -Wformat -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=1 -Wl,-z,now -Wl,-z,relro " CXXFLAGS="-Os -pipe -fno-caller-saves -fno-plt -fhonour-copts -Wno-error=unused-but-set-variable -Wno-error=unused-result -fmacro-prefix-map=/home/build/staging/build_dir/target-x86_64_musl/rust-1.64.0=rust-1.64.0 -Wformat -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=1 -Wl,-z,now -Wl,-z,relro " CPPFLAGS="-I/home/build/staging/staging_dir/toolchain-x86_64_gcc-11.3.0_musl/usr/include -I/home/build/staging/staging_dir/toolchain-x86_64_gcc-11.3.0_musl/include/fortify -I/home/build/staging/staging_dir/toolchain-x86_64_gcc-11.3.0_musl/include " LDFLAGS="-L/home/build/staging/staging_dir/toolchain-x86_64_gcc-11.3.0_musl/usr/lib -L/home/build/staging/staging_dir/toolchain-x86_64_gcc-11.3.0_musl/lib -znow -zrelro "   ./configure --target=x86_64-openwrt-linux --host=x86_64-openwrt-linux --build=x86_64-pc-linux-gnu --program-prefix="" --program-suffix="" --prefix=/usr --exec-prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --libexecdir=/usr/lib --sysconfdir=/etc --datadir=/usr/share --localstatedir=/var --mandir=/usr/man --infodir=/usr/info --disable-nls  ; fi; )
configure: processing command line
configure:
configure: error: Option '--program-prefix=' is not recognized
make[2]: *** [Makefile:128: /home/build/staging/build_dir/target-x86_64_musl/rust-1.64.0/.configured_68b329da9893e34099c7d8ad5cb9c940] Error 1
make[2]: Leaving directory '/home/build/staging/feeds/packages/lang/rust'
time: package/feeds/packages/rust/compile#1.31#1.49#2.84
    ERROR: package/feeds/packages/rust failed to build.
make[1]: *** [package/Makefile:116: package/feeds/packages/rust/compile] Error 1
make[1]: Leaving directory '/home/build/staging'
make: *** [/home/build/staging/include/toplevel.mk:231: package/rust/compile] Error 2

sha256sum

91b33f45ac46790cae91e350e21881020915766d78675fe8d83c8a9d01d0fde6 devel/llvm-project-rustc/Makefile
4237dd900a40d8f7e99f48656b1ad69816f4925cf1f0e4cfa3104f074c44da07 lang/rust/Makefile
9a6682b40582a547db844fee03dad1d11feb31ad2e4c7f420e988ee3c012e8d6 lang/rust_host/Makefile

don't use my changes. why don't you use here

https://github.com/Itus-Shield/packages/

@lucize
Copy link
Contributor

lucize commented Sep 30, 2022

tried the rust-1.59 build, that is only host build (what I need) and failed after a long period of time with

  = note: /usr/bin/ld: cannot find -lz: No such file or directory
          collect2: error: ld returned 1 exit status


error: could not compile `cargo` due to previous error


I doubt that llvm makefile is failing for me, on the new makefile aproach

edit: fixed -lz with apt install zlib1g-dev

@Akira25
Copy link
Contributor

Akira25 commented Sep 30, 2022

@Grommish This PR is almost two years around now. I'd really love to get this into main-branch soon, like most people here. Is there any chance in supporting you in the final steps to take?

@lucize
Copy link
Contributor

lucize commented Oct 1, 2022

for me, https://github.com/Itus-Shield/packages/commits/working is what works and I need, even if it's building everything and takes forever, guess that just updating to latest version will also work
now I only have to see how tu use the actual binaries, I guess some modifications to python is also needed

lu-zero pushed a commit to domo-iot/packages that referenced this pull request Oct 1, 2022
Ripgrep recursively searches directories for a regex pattern while
respecting your gitignore

Requires rust-lang (openwrt#13916)

Signed-off-by: Donald Hoskins <grommish@gmail.com>
@lu-zero
Copy link
Contributor

lu-zero commented Oct 2, 2022

I updated to rust 1.64 here https://github.com/domo-iot/packages/tree/rust-update

After a couple of fixes everything seems working as intended.

lu-zero pushed a commit to domo-iot/packages that referenced this pull request Oct 2, 2022
Ripgrep recursively searches directories for a regex pattern while
respecting your gitignore

Requires rust-lang (openwrt#13916)

Signed-off-by: Donald Hoskins <grommish@gmail.com>
@lu-zero
Copy link
Contributor

lu-zero commented Oct 20, 2022

There is still a bug in the rustc build since it seems to use the wrong dynamic linker when you link external libraries.

@neggles
Copy link
Contributor

neggles commented Oct 22, 2022

Hi all,

I don't know that we can expect Grommish to come back to this one anytime soon. He was using an Azure VM I loaned him for building and testing, and I've just had a look and the last time it was powered on was back in July... I've not seen or heard from him on IRC, either. Hope he's okay.

Regardless, IMO, this PR is not a great way to get Rust in OpenWrt. The overall implementation here is... messy. That's not a reflection on Grommish - debugging toolchain build issues on Rust is not a lot of fun and the documentation is not great, it's impressive that he got this far - but long-term I don't think this is maintainable, and it's horribly inefficient at build-time.

One major thing is, at last check, this PR builds an entire copy of LLVM and two copies of the rust toolchain, rather than starting with a prebuilt binary rustup toolchain and using that to bootstrap the target one; this seemed like it might be necessary at one point, but after digging into how this all works for quite some time, it's not necessary at all. This implementation does some unpleasant things with shared library paths and the like which shouldn't be required either.

I did get partway through building out Rust support in a similar fashion to how golang support is laid out and functions - the rust and golang toolchain build systems follow fairly similar approaches, logically speaking, and the steps are broadly similar - but I haven't had the time or motivation to come back and finish it, not that I got super far.

If you'd like to push this forward, I'd suggest looking at how the golang support has been implemented, and working to build something similar for Rust that involves slightly fewer hackarounds, is a bit more resilient to Rust version changes, and works with a rustup toolchain at the first stage rather than having to compile everything from stage-zero LLVM on down.

That said I certainly don't speak for everyone and I can't speak for Grommish, whether he's here or not, so don't take my word as gospel 😅

@lu-zero
Copy link
Contributor

lu-zero commented Oct 22, 2022

We can try to upstream the other arch targets and have them in the tier-3 as the mips target is already.

@neggles
Copy link
Contributor

neggles commented Oct 25, 2022

Heh... those targets aren't actually necessary either, FWIW. OpenWrt's various arch targets are already covered by existing upstream tuples, and we're building the whole toolchain ourselves anyway so we can use whatever config we like...

@lu-zero
Copy link
Contributor

lu-zero commented Oct 25, 2022

Heh... those targets aren't actually necessary either, FWIW. OpenWrt's various arch targets are already covered by existing upstream tuples, and we're building the whole toolchain ourselves anyway so we can use whatever config we like...

Having them makes our lives a little simpler. once the json targets enter stable we could leverage upstream to install the host compiler and just compile std.

The wrong dynamic linker for the musl targets is yet to be investigated though. Anybody using alpine can check what they are doing?

@lu-zero
Copy link
Contributor

lu-zero commented Nov 7, 2022

I fixed the problem with the dynamic linker, @Grommish do you still have interest in completing it or may I take over?

lu-zero pushed a commit to domo-iot/packages that referenced this pull request Nov 8, 2022
Ripgrep recursively searches directories for a regex pattern while
respecting your gitignore

Requires rust-lang (openwrt#13916)

Signed-off-by: Donald Hoskins <grommish@gmail.com>
@BKPepe BKPepe closed this Nov 8, 2022
lu-zero pushed a commit to domo-iot/packages that referenced this pull request Nov 8, 2022
Ripgrep recursively searches directories for a regex pattern while
respecting your gitignore

Requires rust-lang (openwrt#13916)

Signed-off-by: Donald Hoskins <grommish@gmail.com>
lu-zero pushed a commit to domo-iot/packages that referenced this pull request Nov 26, 2022
Ripgrep recursively searches directories for a regex pattern while
respecting your gitignore

Requires rust-lang (openwrt#13916)

Signed-off-by: Donald Hoskins <grommish@gmail.com>
lu-zero pushed a commit to domo-iot/packages that referenced this pull request Dec 25, 2022
Ripgrep recursively searches directories for a regex pattern while
respecting your gitignore

Requires rust-lang (openwrt#13916)

Signed-off-by: Donald Hoskins <grommish@gmail.com>
lu-zero pushed a commit to domo-iot/packages that referenced this pull request Jan 8, 2023
Ripgrep recursively searches directories for a regex pattern while
respecting your gitignore

Requires rust-lang (openwrt#13916)

Signed-off-by: Donald Hoskins <grommish@gmail.com>
lu-zero pushed a commit to domo-iot/packages that referenced this pull request Jan 15, 2023
Ripgrep recursively searches directories for a regex pattern while
respecting your gitignore

Requires rust-lang (openwrt#13916)

Signed-off-by: Donald Hoskins <grommish@gmail.com>
lu-zero pushed a commit to domo-iot/packages that referenced this pull request Jan 27, 2023
Ripgrep recursively searches directories for a regex pattern while
respecting your gitignore

Requires rust-lang (openwrt#13916)

Signed-off-by: Donald Hoskins <grommish@gmail.com>
lu-zero pushed a commit to domo-iot/packages that referenced this pull request Jan 28, 2023
Ripgrep recursively searches directories for a regex pattern while
respecting your gitignore

Requires rust-lang (openwrt#13916)

Signed-off-by: Donald Hoskins <grommish@gmail.com>
lu-zero pushed a commit to domo-iot/packages that referenced this pull request Feb 6, 2023
Ripgrep recursively searches directories for a regex pattern while
respecting your gitignore

Requires rust-lang (openwrt#13916)

Signed-off-by: Donald Hoskins <grommish@gmail.com>
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 this pull request may close these issues.