From 156107d55a98137b8681f6ff989f7345ec3dbdd2 Mon Sep 17 00:00:00 2001 From: Daniel Mikusa Date: Mon, 10 Apr 2023 08:07:17 -0400 Subject: [PATCH] Add support for Jammy tiny & static stacks Adds support for the tiny and static stacks. Signed-off-by: Daniel Mikusa --- README.md | 18 +++++++++--------- buildpack.toml | 10 ++-------- rustup/build.go | 2 +- rustup/build_test.go | 17 +++++++++++++++-- 4 files changed, 27 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index c977b1e..bc60624 100644 --- a/README.md +++ b/README.md @@ -17,18 +17,18 @@ The buildpack will do the following: * If `rust-toolchain` or `rust-toolchain.toml` exists, `rustup` will install as configured in the file. If `$BP_RUST_TOOLCHAIN` / `$BP_RUST_PROFILE` are also set to non-default values, they will also be installed. * If `rust-toolchain` or `rust-toolchain.toml` do not exist, `rustup` will install `$BP_RUST_TOOLCHAIN` / `$BP_RUST_PROFILE`. * If `$BP_RUST_TARGET` is set, executes `rustup target add` to install an additional Rust target. -* If `$BP_RUST_TARGET` is not set and the build is running on the Paketo Tiny stack, then the Rust Linux musl target will be automatically added. +* If `$BP_RUST_TARGET` is not set and the build is running on the Paketo Tiny or Static stacks, then the Rust Linux musl target will be automatically added. ## Configuration -| Environment Variable | Description | -| ------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `$BP_RUSTUP_ENABLED` | Configure rustup to be enabled. This means that rustup will be used to install Rust. Default value is `true`. Set to false to use another Rust toolchain provider like [rust-dist](https://github.com/paketo-community/rust-dist). | -| `$BP_RUST_TOOLCHAIN` | Rust toolchain to install. Default `stable`. Other common values: `beta`, `nightly` or a specific versin number. Any [acceptable value for a toolchain](https://dev-doc.rust-lang.org/beta/edition-guide/rust-2018/rustup-for-managing-rust-versions.html) can be used here. | -| `$BP_RUST_PROFILE` | Rust profile to install. Default `minimum`. Other acceptable values: `default`, `complete`. See [Rustup docs for profile](https://rust-lang.github.io/rustup/concepts/profiles.html). | -| `$BP_RUST_TARGET` | Additional Rust target to install. Default ``, so nothing additional is installed. If there is no user-specified target and the build is running on the Paketo Tiny stack, then the Linux musl target is automatically added. Run `rustup target list` to see what valid targets exist. | -| `$BP_RUSTUP_INIT_VERSION` | Configure the version of rustup-init to install. It can be a specific version or a wildcard like `1.*`. It defaults to the latest `1.*` version. | -| `$BP_RUSTUP_INIT_LIBC` | Configure the libc implementation used by the installed toolchain. Available options: `gnu` or `musl`. Defaults to `gnu` for compatiblity. You do not need to set this option with the Paketo full/base/tiny stacks. It can be used for compatibility with more exotic or custom stacks. | +| Environment Variable | Description | +| ------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `$BP_RUSTUP_ENABLED` | Configure rustup to be enabled. This means that rustup will be used to install Rust. Default value is `true`. Set to false to use another Rust toolchain provider like [rust-dist](https://github.com/paketo-community/rust-dist). | +| `$BP_RUST_TOOLCHAIN` | Rust toolchain to install. Default `stable`. Other common values: `beta`, `nightly` or a specific versin number. Any [acceptable value for a toolchain](https://dev-doc.rust-lang.org/beta/edition-guide/rust-2018/rustup-for-managing-rust-versions.html) can be used here. | +| `$BP_RUST_PROFILE` | Rust profile to install. Default `minimum`. Other acceptable values: `default`, `complete`. See [Rustup docs for profile](https://rust-lang.github.io/rustup/concepts/profiles.html). | +| `$BP_RUST_TARGET` | Additional Rust target to install. Default ``, so nothing additional is installed. If there is no user-specified target and the build is running on the Paketo Tiny or Static stack, then the Linux musl target is automatically added. Run `rustup target list` to see what valid targets exist. | +| `$BP_RUSTUP_INIT_VERSION` | Configure the version of rustup-init to install. It can be a specific version or a wildcard like `1.*`. It defaults to the latest `1.*` version. | +| `$BP_RUSTUP_INIT_LIBC` | Configure the libc implementation used by the installed toolchain. Available options: `gnu` or `musl`. Defaults to `gnu` for compatiblity. You do not need to set this option with the Paketo full/base/tiny/static stacks. It can be used for compatibility with more exotic or custom stacks. | ## License diff --git a/buildpack.toml b/buildpack.toml index de2e39f..cbb0974 100644 --- a/buildpack.toml +++ b/buildpack.toml @@ -73,7 +73,7 @@ api = "0.7" name = "Rustup (GNU libc)" purl = "pkg:generic/rustup@1.25.2" sha256 = "bb31eaf643926b2ee9f4d8d6fc0e2835e03c0a60f34d324048aa194f0b29a71c" - stacks = ["io.buildpacks.stacks.bionic", "io.paketo.stacks.tiny", "*"] + stacks = ["*"] uri = "https://static.rust-lang.org/rustup/archive/1.25.2/x86_64-unknown-linux-gnu/rustup-init" version = "1.25.2" @@ -91,7 +91,7 @@ api = "0.7" name = "Rustup (musl libc)" purl = "pkg:generic/rustup@1.25.2" sha256 = "241a99ff02accd2e8e0ef3a46aaa59f8d6934b1bb6e4fba158e1806ae028eb25" - stacks = ["io.buildpacks.stacks.bionic", "io.paketo.stacks.tiny", "*"] + stacks = ["*"] uri = "https://static.rust-lang.org/rustup/archive/1.25.2/x86_64-unknown-linux-musl/rustup-init" version = "1.25.2" @@ -103,11 +103,5 @@ api = "0.7" type = "MIT" uri = "https://github.com/rust-lang/rustup/blob/master/LICENSE-MIT" -[[stacks]] - id = "io.buildpacks.stacks.bionic" - -[[stacks]] - id = "io.paketo.stacks.tiny" - [[stacks]] id = "*" diff --git a/rustup/build.go b/rustup/build.go index 8a01dfd..4c23811 100644 --- a/rustup/build.go +++ b/rustup/build.go @@ -120,7 +120,7 @@ func AdditionalTarget(cr libpak.ConfigurationResolver, stack string) string { } libc := "gnu" - if stack == libpak.TinyStackID { + if libpak.IsTinyStack(stack) || libpak.IsStaticStack(stack) { libc = "musl" } diff --git a/rustup/build_test.go b/rustup/build_test.go index 79a2e58..61a0e5d 100644 --- a/rustup/build_test.go +++ b/rustup/build_test.go @@ -220,12 +220,25 @@ func testBuild(t *testing.T, context spec.G, it spec.S) { ctx.Buildpack.Metadata = map[string]interface{}{ "configurations": []map[string]interface{}{}, } - ctx.StackID = libpak.TinyStackID + ctx.StackID = libpak.BionicTinyStackID cr, err := libpak.NewConfigurationResolver(ctx.Buildpack, nil) Expect(err).ToNot(HaveOccurred()) - target := rustup.AdditionalTarget(cr, libpak.TinyStackID) + target := rustup.AdditionalTarget(cr, libpak.BionicTinyStackID) + Expect(target).To(HaveSuffix("-unknown-linux-musl")) + }) + + it("picks musl for static stack", func() { + ctx.Buildpack.Metadata = map[string]interface{}{ + "configurations": []map[string]interface{}{}, + } + ctx.StackID = libpak.JammyStaticStackID + + cr, err := libpak.NewConfigurationResolver(ctx.Buildpack, nil) + Expect(err).ToNot(HaveOccurred()) + + target := rustup.AdditionalTarget(cr, libpak.JammyStaticStackID) Expect(target).To(HaveSuffix("-unknown-linux-musl")) }) })