diff mbox series

[v3] rust: Enable building rust from stable, beta and nightly channels

Message ID 20221217162057.1377465-1-alejandro@enedino.org
State Accepted, archived
Commit 807a52686682d0d0a151ea3dadd99880feb67cc0
Headers show
Series [v3] rust: Enable building rust from stable, beta and nightly channels | expand

Commit Message

Alejandro Enedino Hernandez Samaniego Dec. 17, 2022, 4:20 p.m. UTC
From: Alejandro Hernandez Samaniego <alejandro@enedino.org>

Rust follows the train release model via the stable, beta and nightly channels,
by default we build rust from the stable channel, however there are certain
features which are only available in the beta or nightly channels.

Make these channels available by setting a RUST_CHANNEL variable which defaults
to stable making this change transparent to the user.

The snapshot version used by rust during its compilation wont necessarily match
the version being built, specially if were building from an unstable channel,
to avoid confusion rename this to SNAPSHOT_VERSION and use RUST_VERSION for the
version to be built, which is automatically defined to PV.

Append -beta or -nightly to rusts PV for signature awareness.

It is important to note that this does not build rust from the beta/nightly
published tarball (which today build rust v1.67.0 and v1.68.0 respectively),
instead this builds rust from the current selected version (1.66.0) and enables
the beta/nightly features for that version.

Setting the variable RUST_CHANNEL=nightly results in the following:

$ rustc -Vv
rustc 1.66.0-nightly

Signed-off-by: Alejandro Hernandez Samaniego <alejandro@enedino.org>
---
 meta/recipes-devtools/rust/rust-snapshot.inc | 7 ++++---
 meta/recipes-devtools/rust/rust-source.inc   | 5 +++--
 meta/recipes-devtools/rust/rust.inc          | 6 +++++-
 3 files changed, 12 insertions(+), 6 deletions(-)

Comments

Alex Kiernan Dec. 19, 2022, 10:23 a.m. UTC | #1
On Sat, Dec 17, 2022 at 4:21 PM Alejandro Hernandez Samaniego
<alejandro@enedino.org> wrote:
>
> From: Alejandro Hernandez Samaniego <alejandro@enedino.org>
>
> Rust follows the train release model via the stable, beta and nightly channels,
> by default we build rust from the stable channel, however there are certain
> features which are only available in the beta or nightly channels.
>
> Make these channels available by setting a RUST_CHANNEL variable which defaults
> to stable making this change transparent to the user.
>
> The snapshot version used by rust during its compilation wont necessarily match
> the version being built, specially if were building from an unstable channel,
> to avoid confusion rename this to SNAPSHOT_VERSION and use RUST_VERSION for the
> version to be built, which is automatically defined to PV.
>
> Append -beta or -nightly to rusts PV for signature awareness.
>
> It is important to note that this does not build rust from the beta/nightly
> published tarball (which today build rust v1.67.0 and v1.68.0 respectively),
> instead this builds rust from the current selected version (1.66.0) and enables
> the beta/nightly features for that version.
>
> Setting the variable RUST_CHANNEL=nightly results in the following:
>
> $ rustc -Vv
> rustc 1.66.0-nightly
>

I think there's an existing problem which means you're probably still
not getting quite what you wanted here... I think libstd-rs build
ought to be affected by this, but as far as I can tell won't be,
because we're building it with cargo, not as part of the bootstrap
process (and I've failed to find any documentation which suggests
building with cargo is "supported"). I've no idea if that means you
could end up with something which is subtly broken.

That said, my attempts to switch the way the standard library gets
built over the weekend failed miserably.

--
Alex Kiernan
Alejandro Enedino Hernandez Samaniego Dec. 19, 2022, 4:30 p.m. UTC | #2
Yes, and no, you're right the std library's might be affected by this in
some way
(at least I believe it might but I haven't seen an actual problem using the
 libstd-rs recipe), either way, if a problem arises its easily solvable
because
that's actually one of the features that comes with this, the build-std
feature
builds the std library as part of the crate compilation process, this way
 you end up with a newly built corresponding std library.

On Mon, Dec 19, 2022, 4:24 AM Alex Kiernan <alex.kiernan@gmail.com> wrote:

> On Sat, Dec 17, 2022 at 4:21 PM Alejandro Hernandez Samaniego
> <alejandro@enedino.org> wrote:
> >
> > From: Alejandro Hernandez Samaniego <alejandro@enedino.org>
> >
> > Rust follows the train release model via the stable, beta and nightly
> channels,
> > by default we build rust from the stable channel, however there are
> certain
> > features which are only available in the beta or nightly channels.
> >
> > Make these channels available by setting a RUST_CHANNEL variable which
> defaults
> > to stable making this change transparent to the user.
> >
> > The snapshot version used by rust during its compilation wont
> necessarily match
> > the version being built, specially if were building from an unstable
> channel,
> > to avoid confusion rename this to SNAPSHOT_VERSION and use RUST_VERSION
> for the
> > version to be built, which is automatically defined to PV.
> >
> > Append -beta or -nightly to rusts PV for signature awareness.
> >
> > It is important to note that this does not build rust from the
> beta/nightly
> > published tarball (which today build rust v1.67.0 and v1.68.0
> respectively),
> > instead this builds rust from the current selected version (1.66.0) and
> enables
> > the beta/nightly features for that version.
> >
> > Setting the variable RUST_CHANNEL=nightly results in the following:
> >
> > $ rustc -Vv
> > rustc 1.66.0-nightly
> >
>
> I think there's an existing problem which means you're probably still
> not getting quite what you wanted here... I think libstd-rs build
> ought to be affected by this, but as far as I can tell won't be,
> because we're building it with cargo, not as part of the bootstrap
> process (and I've failed to find any documentation which suggests
> building with cargo is "supported"). I've no idea if that means you
> could end up with something which is subtly broken.
>
> That said, my attempts to switch the way the standard library gets
> built over the weekend failed miserably.
>
> --
> Alex Kiernan
>
diff mbox series

Patch

diff --git a/meta/recipes-devtools/rust/rust-snapshot.inc b/meta/recipes-devtools/rust/rust-snapshot.inc
index 222f34f9a8..6420bcff55 100644
--- a/meta/recipes-devtools/rust/rust-snapshot.inc
+++ b/meta/recipes-devtools/rust/rust-snapshot.inc
@@ -5,7 +5,8 @@ 
 ## The version is replicated here.
 ## TODO: find a way to add additional SRC_URIs based on the contents of an
 ##       earlier SRC_URI.
-RS_VERSION = "1.65.0"
+
+SNAPSHOT_VERSION = "1.65.0"
 CARGO_VERSION = "1.65.0"
 
 # TODO: Add hashes for other architecture toolchains as well. Make a script?
@@ -27,6 +28,6 @@  SRC_URI += " \
     https://static.rust-lang.org/dist/${CARGO_SNAPSHOT}.tar.xz;name=cargo-snapshot-${RUST_BUILD_ARCH};subdir=rust-snapshot-components \
 "
 
-RUST_STD_SNAPSHOT = "rust-std-${RS_VERSION}-${RUST_BUILD_ARCH}-unknown-linux-gnu"
-RUSTC_SNAPSHOT = "rustc-${RS_VERSION}-${RUST_BUILD_ARCH}-unknown-linux-gnu"
+RUST_STD_SNAPSHOT = "rust-std-${SNAPSHOT_VERSION}-${RUST_BUILD_ARCH}-unknown-linux-gnu"
+RUSTC_SNAPSHOT = "rustc-${SNAPSHOT_VERSION}-${RUST_BUILD_ARCH}-unknown-linux-gnu"
 CARGO_SNAPSHOT = "cargo-${CARGO_VERSION}-${RUST_BUILD_ARCH}-unknown-linux-gnu"
diff --git a/meta/recipes-devtools/rust/rust-source.inc b/meta/recipes-devtools/rust/rust-source.inc
index 1c511917e2..91a6c5a942 100644
--- a/meta/recipes-devtools/rust/rust-source.inc
+++ b/meta/recipes-devtools/rust/rust-source.inc
@@ -1,4 +1,5 @@ 
-SRC_URI += "https://static.rust-lang.org/dist/rustc-${PV}-src.tar.xz;name=rust"
+RUST_VERSION ?= "${@d.getVar('PV').split('-')[0]}"
+SRC_URI += "https://static.rust-lang.org/dist/rustc-${RUST_VERSION}-src.tar.xz;name=rust"
 SRC_URI[rust.sha256sum] = "0dc176e34fae9871f855a6ba4cb30fa19d69c5b4428d29281a07419c4950715c"
 
 SRC_URI:append:class-target:pn-rust = " \
@@ -6,7 +7,7 @@  SRC_URI:append:class-target:pn-rust = " \
     file://crossbeam_atomic.patch"
 SRC_URI:append:class-nativesdk:pn-nativesdk-rust = " file://hardcodepaths.patch"
 
-RUSTSRC = "${WORKDIR}/rustc-${PV}-src"
+RUSTSRC = "${WORKDIR}/rustc-${RUST_VERSION}-src"
 
 UPSTREAM_CHECK_URI = "https://forge.rust-lang.org/infra/other-installation-methods.html"
 UPSTREAM_CHECK_REGEX = "rustc-(?P<pver>\d+(\.\d+)+)-src"
diff --git a/meta/recipes-devtools/rust/rust.inc b/meta/recipes-devtools/rust/rust.inc
index 8d25e7993a..f58aa46444 100644
--- a/meta/recipes-devtools/rust/rust.inc
+++ b/meta/recipes-devtools/rust/rust.inc
@@ -13,6 +13,10 @@  DEPENDS:append:class-nativesdk = " nativesdk-rust-llvm"
 
 S = "${RUSTSRC}"
 
+# Use at your own risk, accepted values are stable, beta and nightly
+RUST_CHANNEL ?= "stable"
+PV .= "${@bb.utils.contains('RUST_CHANNEL', 'stable', '', '-${RUST_CHANNEL}', d)}"
+
 export FORCE_CRATE_HASH="${BB_TASKHASH}"
 
 RUST_ALTERNATE_EXE_PATH ?= "${STAGING_LIBDIR}/llvm-rust/bin/llvm-config"
@@ -116,7 +120,7 @@  python do_configure() {
     # [rust]
     config.add_section("rust")
     config.set("rust", "rpath", e(True))
-    config.set("rust", "channel", e("stable"))
+    config.set("rust", "channel", e(d.expand("${RUST_CHANNEL}")))
 
     # Whether or not to optimize the compiler and standard library
     config.set("rust", "optimize", e(True))