Skip to content

Commit

Permalink
Update Cargo/crates.io Sparse Index support
Browse files Browse the repository at this point in the history
The environment variable for Cargo/crates.io sparse index support has changed to `CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse`. This PR updates that functionality. It is still enabled by default, but requires beta or nightly Rust to work. This should just start working when upstream Rust supports this in stable.

Signed-off-by: Daniel Mikusa <[email protected]>
  • Loading branch information
dmikusa authored and ForestEckhardt committed Feb 6, 2023
1 parent bfe5c05 commit 174a319
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions cargo/cargo.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,8 @@ func (c Cargo) Contribute(layer libcnb.Layer) (libcnb.Layer, error) {
return libcnb.Layer{}, fmt.Errorf("unable to find CARGO_HOME, it must be set")
}

if err := os.Setenv("CARGO_UNSTABLE_SPARSE_REGISTRY", "true"); err != nil {
return libcnb.Layer{}, fmt.Errorf("unable to set CARGO_UNSTABLE_SPARSE_REGISTRY\n%w", err)
if err := os.Setenv("CARGO_REGISTRIES_CRATES_IO_PROTOCOL", "sparse"); err != nil {
return libcnb.Layer{}, fmt.Errorf("unable to set CARGO_REGISTRIES_CRATES_IO_PROTOCOL\n%w", err)
}

if err = preserver.RestoreAll(targetPath, cargoHome, layer.Path); err != nil {
Expand Down
14 changes: 7 additions & 7 deletions cargo/cargo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ func testCargo(t *testing.T, context spec.G, it spec.S) {
_, err = c.Contribute(inputLayer)
Expect(err).NotTo(HaveOccurred())

Expect(os.Getenv("CARGO_UNSTABLE_SPARSE_REGISTRY")).To(Equal("true"))
Expect(os.Getenv("CARGO_REGISTRIES_CRATES_IO_PROTOCOL")).To(Equal("sparse"))

Expect(service.Calls[2].Method).To(Equal("InstallTool"))
Expect(service.Calls[2].Arguments[0]).To(Equal("foo-tool"))
Expand Down Expand Up @@ -343,7 +343,7 @@ func testCargo(t *testing.T, context spec.G, it spec.S) {
outputLayer, err := c.Contribute(inputLayer)
Expect(err).NotTo(HaveOccurred())

Expect(os.Getenv("CARGO_UNSTABLE_SPARSE_REGISTRY")).To(Equal("true"))
Expect(os.Getenv("CARGO_REGISTRIES_CRATES_IO_PROTOCOL")).To(Equal("sparse"))

sbomScanner.AssertCalled(t, "ScanLayer", inputLayer, ctx.Application.Path, libcnb.CycloneDXJSON, libcnb.SyftJSON)

Expand Down Expand Up @@ -390,7 +390,7 @@ func testCargo(t *testing.T, context spec.G, it spec.S) {
outputLayer, err := c.Contribute(inputLayer)
Expect(err).NotTo(HaveOccurred())

Expect(os.Getenv("CARGO_UNSTABLE_SPARSE_REGISTRY")).To(Equal("true"))
Expect(os.Getenv("CARGO_REGISTRIES_CRATES_IO_PROTOCOL")).To(Equal("sparse"))

sbomScanner.AssertCalled(t, "ScanLayer", inputLayer, ctx.Application.Path, libcnb.CycloneDXJSON, libcnb.SyftJSON)

Expand Down Expand Up @@ -437,7 +437,7 @@ func testCargo(t *testing.T, context spec.G, it spec.S) {
outputLayer, err := c.Contribute(inputLayer)
Expect(err).NotTo(HaveOccurred())

Expect(os.Getenv("CARGO_UNSTABLE_SPARSE_REGISTRY")).To(Equal("true"))
Expect(os.Getenv("CARGO_REGISTRIES_CRATES_IO_PROTOCOL")).To(Equal("sparse"))

sbomScanner.AssertNotCalled(t, "ScanLayer", inputLayer, ctx.Application.Path, libcnb.CycloneDXJSON, libcnb.SyftJSON)

Expand Down Expand Up @@ -489,7 +489,7 @@ func testCargo(t *testing.T, context spec.G, it spec.S) {
outputLayer, err := c.Contribute(inputLayer)
Expect(err).NotTo(HaveOccurred())

Expect(os.Getenv("CARGO_UNSTABLE_SPARSE_REGISTRY")).To(Equal("true"))
Expect(os.Getenv("CARGO_REGISTRIES_CRATES_IO_PROTOCOL")).To(Equal("sparse"))

sbomScanner.AssertCalled(t, "ScanLayer", inputLayer, ctx.Application.Path, libcnb.CycloneDXJSON, libcnb.SyftJSON)

Expand Down Expand Up @@ -539,7 +539,7 @@ func testCargo(t *testing.T, context spec.G, it spec.S) {
outputLayer, err := c.Contribute(inputLayer)
Expect(err).NotTo(HaveOccurred())

Expect(os.Getenv("CARGO_UNSTABLE_SPARSE_REGISTRY")).To(Equal("true"))
Expect(os.Getenv("CARGO_REGISTRIES_CRATES_IO_PROTOCOL")).To(Equal("sparse"))

sbomScanner.AssertCalled(t, "ScanLayer", inputLayer, ctx.Application.Path, libcnb.CycloneDXJSON, libcnb.SyftJSON)

Expand Down Expand Up @@ -653,7 +653,7 @@ func testCargo(t *testing.T, context spec.G, it spec.S) {
outputLayer, err := c.Contribute(inputLayer)
Expect(err).NotTo(HaveOccurred())

Expect(os.Getenv("CARGO_UNSTABLE_SPARSE_REGISTRY")).To(Equal("true"))
Expect(os.Getenv("CARGO_REGISTRIES_CRATES_IO_PROTOCOL")).To(Equal("sparse"))

Expect(outputLayer.LayerTypes.Cache).To(BeTrue())
Expect(outputLayer.LayerTypes.Build).To(BeFalse())
Expand Down

0 comments on commit 174a319

Please sign in to comment.