Skip to content

Commit

Permalink
Merge pull request #306 from oasisprotocol/matevz/fix/rofl-build-depe…
Browse files Browse the repository at this point in the history
…ndency-error

cargo: Dump stderr on compilation error
  • Loading branch information
matevz authored Oct 11, 2024
2 parents 6e2926c + 5e43015 commit 2fbc901
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion build/cargo/cargo.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
package cargo

import (
"bytes"
"encoding/json"
"fmt"
"os/exec"
Expand Down Expand Up @@ -64,10 +65,14 @@ func Build(release bool, target string, features []string) (string, error) {
args = append(args, "--message-format", "json")

cmd := exec.Command("cargo", args...)
// Parse stdout JSON messages and store stderr to buffer.
stdout, err := cmd.StdoutPipe()
if err != nil {
return "", fmt.Errorf("failed to initialize build process: %w", err)
}
var stderr bytes.Buffer
cmd.Stderr = &stderr

if err = cmd.Start(); err != nil {
return "", fmt.Errorf("failed to start build process: %w", err)
}
Expand Down Expand Up @@ -105,7 +110,7 @@ func Build(release bool, target string, features []string) (string, error) {
}
}
if err = cmd.Wait(); err != nil {
return "", fmt.Errorf("build process failed: %w", err)
return "", fmt.Errorf("build process failed: %w\nStandard error output:\n%s", err, stderr.String())
}

if executable == "" {
Expand Down

0 comments on commit 2fbc901

Please sign in to comment.