Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions e2e/language/rust_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright 2025 The envd Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package language

import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

"github.com/tensorchord/envd/e2e"
)

var _ = Describe("rust", Ordered, func() {
exampleName := "rust"
testcase := "e2e"
Describe("Should install rust lang successfully", func() {
e := e2e.NewExample(e2e.BuildContextDirWithName(exampleName), testcase)
BeforeAll(e.BuildImage(true))
BeforeEach(e.RunContainer())
It("Should have cargo installed", func() {
res, err := e.ExecRuntimeCommand("show")
Expect(err).To(BeNil())
Expect(res).To(ContainSubstring("cargo"))
})
AfterEach(e.DestroyContainer())
})
})
12 changes: 12 additions & 0 deletions e2e/language/testdata/rust/build.envd
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# syntax=v1


def build():
base(dev=True)
install.rust()
shell("fish")
runtime.command(
commands={
"show": "cargo version",
}
)
9 changes: 9 additions & 0 deletions envd/api/v1/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,15 @@ def julia():
"""Install Julia."""


def rust(version: Optional[str] = None):
"""Install Rust programming language.

Args:
version (Optional[str]): Rust version, such as '1.72.0'.
If not specified, the latest stable version will be installed.
"""


def apt_packages(name: Sequence[str] = ()):
"""Install package using the system package manager (apt on Ubuntu).

Expand Down
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/tensorchord/envd

go 1.24.6
go 1.25.1

require (
github.com/Pallinder/go-randomdata v1.2.0
Expand Down Expand Up @@ -235,7 +235,6 @@ require (
go.opentelemetry.io/otel/sdk/metric v1.38.0 // indirect
go.opentelemetry.io/otel/trace v1.38.0 // indirect
go.opentelemetry.io/proto/otlp v1.8.0 // indirect
go.uber.org/automaxprocs v1.6.0 // indirect
go.yaml.in/yaml/v2 v2.4.3 // indirect
go.yaml.in/yaml/v3 v3.0.4 // indirect
golang.org/x/mod v0.29.0 // indirect
Expand Down
80 changes: 22 additions & 58 deletions go.sum

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions pkg/lang/frontend/starlark/v1/install/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const (
rulePixi = "install.pixi"
ruleRLang = "install.r_lang"
ruleJulia = "install.julia"
ruleRust = "install.rust"

// packages
ruleSystemPackage = "install.apt_packages"
Expand Down
14 changes: 14 additions & 0 deletions pkg/lang/frontend/starlark/v1/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ var Module = &starlarkstruct.Module{
"pixi": starlark.NewBuiltin(rulePixi, ruleFuncPixi),
"r_lang": starlark.NewBuiltin(ruleRLang, ruleFuncRLang),
"julia": starlark.NewBuiltin(ruleJulia, ruleFuncJulia),
"rust": starlark.NewBuiltin(ruleRust, ruleFuncRust),
// packages
"apt_packages": starlark.NewBuiltin(ruleSystemPackage, ruleFuncSystemPackage),
"python_packages": starlark.NewBuiltin(rulePyPIPackage, ruleFuncPyPIPackage),
Expand Down Expand Up @@ -122,6 +123,19 @@ func ruleFuncJulia(thread *starlark.Thread, _ *starlark.Builtin,
return starlark.None, nil
}

func ruleFuncRust(thread *starlark.Thread, _ *starlark.Builtin,
args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error) {
logger.Debugf("rule `%s` is invoked", ruleRust)

var version *string
if err := starlark.UnpackArgs(ruleRust, args, kwargs, "version?", version); err != nil {
Comment thread
kemingy marked this conversation as resolved.
Outdated
return nil, err
}

ir.Rust(version)
return starlark.None, nil
}

func ruleFuncPyPIPackage(thread *starlark.Thread, _ *starlark.Builtin,
args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error) {
var name *starlark.List
Expand Down
9 changes: 9 additions & 0 deletions pkg/lang/ir/v1/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,15 @@ func Julia() {
})
}

func Rust(version *string) {
g := DefaultGraph.(*generalGraph)

g.Languages = append(g.Languages, ir.Language{
Name: "rust",
Version: version,
})
}

func PyPIPackage(deps []string, requirementsFile string, wheels []string) error {
g := DefaultGraph.(*generalGraph)

Expand Down
50 changes: 50 additions & 0 deletions pkg/lang/ir/v1/rust.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright 2025 The envd Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package v1

import (
"github.com/moby/buildkit/client/llb"
)

const (
RustDefaultVersion = "latest"
RustUpInitFilePath = "/tmp/rustup-init.sh"
CargoHomeDir = "/opt/rust"
CargoHomeBin = "/opt/rust/bin"
)

func (g *generalGraph) installRust(root llb.State, version *string) llb.State {
base := llb.Image(builderImage)
builder := base.Run(
llb.Shlexf(`sh -c "curl --proto '=https' --tlsv1.2 -sSf -o %s https://sh.rustup.rs"`, RustUpInitFilePath),
llb.WithCustomName("[internal] download rustup-init.sh"),
).Root()
root = root.File(
llb.Copy(builder, RustUpInitFilePath, RustUpInitFilePath),
llb.WithCustomName("[internal] copy the rustup-init.sh"),
)
if version != nil {
root = root.AddEnv("RUSTUP_VERSION", *version)
}
root = root.AddEnv("CARGO_HOME", CargoHomeDir).File(
llb.Mkdir(CargoHomeDir, 0755, llb.WithParents(true), llb.WithUIDGID(g.uid, g.gid)),
llb.WithCustomNamef("[internal] create cargo dir: %s", CargoHomeDir),
).Run(
llb.Shlexf(`sh -c "sh %[1]s -y -q --no-modify-path && rm %[1]s"`, RustUpInitFilePath),
llb.WithCustomName("[internal] install rust"),
).Root()
g.RuntimeEnvPaths = append(g.RuntimeEnvPaths, CargoHomeBin)
return root
}
4 changes: 4 additions & 0 deletions pkg/lang/ir/v1/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ func (g *generalGraph) compileLanguage(root llb.State) (llb.State, error) {
root = g.installRLang(root)
case "julia":
root = g.installJulia(root)
case "rust":
root = g.installRust(root, language.Version)
}
}
return root, err
Expand All @@ -182,6 +184,8 @@ func (g *generalGraph) compileLanguage(root llb.State) (llb.State, error) {
lang = g.installRLang(root)
case "julia":
lang = g.installJulia(root)
case "rust":
lang = g.installRust(root, language.Version)
}
langs = append(langs, lang)
}
Expand Down
Loading