Skip to content

Commit

Permalink
Merge pull request #250 from samj1912/inflate-rust
Browse files Browse the repository at this point in the history
Correctly inflate rust-dist
  • Loading branch information
dmikusa authored Jun 26, 2023
2 parents 7297de7 + 9700142 commit 3188ea9
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 8 deletions.
26 changes: 22 additions & 4 deletions rust/rust.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ package rust
import (
"fmt"
"os"
"path"

"github.com/buildpacks/libcnb"

"github.com/paketo-buildpacks/libpak"
"github.com/paketo-buildpacks/libpak/bard"
"github.com/paketo-buildpacks/libpak/crush"
"github.com/paketo-buildpacks/libpak/effect"
)

type Rust struct {
Expand All @@ -34,13 +37,28 @@ func NewRust(dependency libpak.BuildpackDependency, cache libpak.DependencyCache

func (j Rust) Contribute(layer libcnb.Layer) (libcnb.Layer, error) {
j.LayerContributor.Logger = j.Logger

return j.LayerContributor.Contribute(layer, func(artifact *os.File) (libcnb.Layer, error) {
j.Logger.Bodyf("Expanding to %s", layer.Path)
if err := crush.Extract(artifact, layer.Path, 1); err != nil {
tempDir, err := os.MkdirTemp("", "rust")
if err != nil {
return libcnb.Layer{}, fmt.Errorf("unable to create temporary directory to expand Rust\n%w", err)
}
if err := crush.Extract(artifact, tempDir, 1); err != nil {
return libcnb.Layer{}, fmt.Errorf("unable to expand Rust\n%w", err)
}

executor := effect.NewExecutor()
j.Logger.Bodyf("Expanding to %s", layer.Path)
if err = executor.Execute(effect.Execution{
Command: "./install.sh",
Args: []string{fmt.Sprintf("--prefix=%s", layer.Path), "--disable-ldconfig"},
Dir: tempDir,
Stdout: bard.NewWriter(j.Logger.Logger.InfoWriter(), bard.WithIndent(3)),
Stderr: bard.NewWriter(j.Logger.Logger.InfoWriter(), bard.WithIndent(3)),
}); err != nil {
return libcnb.Layer{}, fmt.Errorf("unable to install rust: %w", err)
}
if err = os.RemoveAll(path.Join(layer.Path, "share")); err != nil {
return libcnb.Layer{}, fmt.Errorf("unable to trim rust installation: %w", err)
}
return layer, nil
})
}
Expand Down
3 changes: 2 additions & 1 deletion rust/rust_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func testRust(t *testing.T, context spec.G, it spec.S) {
dep := libpak.BuildpackDependency{
Version: "1.54.0",
URI: "https://localhost/stub-rust-1.54.0.tar.gz",
SHA256: "e40a6ddb7d74d78a6d5557380160a174b1273813db1caf9b1f7bcbfe1578e818",
SHA256: "2b61f788c000462840d4bf0f83f5ad3d552a8d27f364dd5f7e7e6b29031bee43",
}
dc := libpak.DependencyCache{CachePath: "testdata"}

Expand All @@ -53,6 +53,7 @@ func testRust(t *testing.T, context spec.G, it spec.S) {
Expect(layer.LayerTypes.Cache).To(BeTrue())

Expect(filepath.Join(layer.Path, "fixture-marker")).To(BeARegularFile())
Expect(filepath.Join(layer.Path, "bin")).To(BeADirectory())
Expect(layer.SBOMPath(libcnb.SyftJSON)).To(BeARegularFile())
})
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
version = "1.54.0"
uri = "https://localhost/stub-rust-1.54.0.tar.gz"
sha256 = "2b61f788c000462840d4bf0f83f5ad3d552a8d27f364dd5f7e7e6b29031bee43"
Binary file not shown.

This file was deleted.

Binary file not shown.

0 comments on commit 3188ea9

Please sign in to comment.