Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support cargo workspaces #172

Merged
merged 1 commit into from
Nov 24, 2020
Merged
Changes from all 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
11 changes: 8 additions & 3 deletions pkg/compute/rust.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,13 @@ func (m *CargoManifest) Read(filename string) error {
// CargoMetadata models information about the workspace members and resolved
// dependencies of the current package via `cargo metadata` command output.
type CargoMetadata struct {
Package []CargoPackage `json:"packages"`
Package []CargoPackage `json:"packages"`
TargetDirectory string `json:"target_directory"`
}

// Read the contents of the Cargo.lock file from filename.
func (m *CargoMetadata) Read() error {
cmd := exec.Command("cargo", "metadata", "--format-version", "1")
cmd := exec.Command("cargo", "metadata", "--quiet", "--format-version", "1")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reason for adding the --quiet flag here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It suppresses some warnings, esp. for workspaces, like:

$ cargo metadata --format-version 1 > /dev/null
warning: profiles for the non root package will be ignored, specify profiles at the workspace root:
package:   /Users/goro-fuji/ghq/github.com/gfx/ecp-hello/app/Cargo.toml
workspace: /Users/goro-fuji/ghq/github.com/gfx/ecp-ecp-hello/Cargo.toml

It doesn't affect the fastly cli but I feel it's better to suppress.

stdout, err := cmd.StdoutPipe()
if err != nil {
return err
Expand Down Expand Up @@ -305,7 +306,11 @@ func (r Rust) Build(out io.Writer, verbose bool) error {
if err != nil {
return fmt.Errorf("getting current working directory: %w", err)
}
src := filepath.Join(dir, "target", WasmWasiTarget, "release", fmt.Sprintf("%s.wasm", binName))
var metadata CargoMetadata
if err := metadata.Read(); err != nil {
return fmt.Errorf("error reading cargo metadata: %w", err)
}
src := filepath.Join(metadata.TargetDirectory, WasmWasiTarget, "release", fmt.Sprintf("%s.wasm", binName))
dst := filepath.Join(dir, "bin", "main.wasm")

// Check if bin directory exists and create if not.
Expand Down