Skip to content

Commit df04d4e

Browse files
authored
Merge pull request #548 from oasisprotocol/matevz/fix/rofl-sgx-build
- sgx-raw builds can now be built with the rofl-dev builder - a new verbose switch `-v` was introduced which prints out exact build commands - `Cargo.lock` is now overwritten/regenerated by default and the `--locked` switch is passed only in the `oasis rofl build --verify` mode - trust root is optional for debug builds - `oasis rofl create` now also supports `--no-update-manifest` switch if you simply want to register a new rofl app
2 parents c01b7ad + 486de10 commit df04d4e

9 files changed

Lines changed: 80 additions & 25 deletions

File tree

build/cargo/cargo.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"strings"
1111

1212
"github.com/oasisprotocol/cli/build/env"
13+
"github.com/oasisprotocol/cli/cmd/common"
1314
)
1415

1516
// Metadata is the cargo package metadata.
@@ -53,6 +54,9 @@ func GetMetadata(env env.ExecEnv) (*Metadata, error) {
5354
if err = env.WrapCommand(cmd); err != nil {
5455
return nil, err
5556
}
57+
if common.IsVerbose() {
58+
fmt.Println(cmd)
59+
}
5660
if err = cmd.Start(); err != nil {
5761
return nil, fmt.Errorf("failed to start metadata process: %w", err)
5862
}
@@ -110,11 +114,14 @@ func GetMetadata(env env.ExecEnv) (*Metadata, error) {
110114
}
111115

112116
// Build builds a Rust program using `cargo` in the current working directory.
113-
func Build(env env.ExecEnv, release bool, target string, features []string) (string, error) {
114-
args := []string{"build", "--locked"}
117+
func Build(env env.ExecEnv, release, locked bool, target string, features []string) (string, error) {
118+
args := []string{"build"}
115119
if release {
116120
args = append(args, "--release")
117121
}
122+
if locked {
123+
args = append(args, "--locked")
124+
}
118125
if target != "" {
119126
args = append(args, "--target", target)
120127
}
@@ -136,6 +143,9 @@ func Build(env env.ExecEnv, release bool, target string, features []string) (str
136143
if err = env.WrapCommand(cmd); err != nil {
137144
return "", err
138145
}
146+
if common.IsVerbose() {
147+
fmt.Println(cmd)
148+
}
139149
if err = cmd.Start(); err != nil {
140150
return "", fmt.Errorf("failed to start build process: %w", err)
141151
}

build/env/env.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import (
66
"os/exec"
77
"path/filepath"
88
"strings"
9+
10+
"github.com/oasisprotocol/cli/cmd/common"
911
)
1012

1113
// ExecEnv is an execution environment.
@@ -192,6 +194,9 @@ func (de *DockerEnv) FixPermissions(path string) error {
192194
if err = de.WrapCommand(cmd); err != nil {
193195
return err
194196
}
197+
if common.IsVerbose() {
198+
fmt.Println(cmd)
199+
}
195200
return cmd.Run()
196201
}
197202

build/sgxs/sgxs.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,25 @@
22
package sgxs
33

44
import (
5+
"fmt"
56
"os/exec"
67
"strconv"
78

89
"github.com/oasisprotocol/cli/build/env"
10+
"github.com/oasisprotocol/cli/cmd/common"
911
)
1012

1113
// Elf2Sgxs converts an ELF binary built for the SGX ABI into an SGXS binary.
1214
//
1315
// It requires the `ftxsgx-elf2sgxs` utility to be installed.
14-
func Elf2Sgxs(buildEnv env.ExecEnv, elfSgxPath, sgxsPath string, heapSize, stackSize, threads uint64) error {
16+
func Elf2Sgxs(buildEnv env.ExecEnv, elfSgxPath, sgxsPath string, heapSize, stackSize, threads uint64) (err error) {
17+
if elfSgxPath, err = buildEnv.PathToEnv(elfSgxPath); err != nil {
18+
return
19+
}
20+
if sgxsPath, err = buildEnv.PathToEnv(sgxsPath); err != nil {
21+
return
22+
}
23+
1524
args := []string{
1625
elfSgxPath,
1726
"--heap-size", strconv.FormatUint(heapSize, 10),
@@ -21,8 +30,11 @@ func Elf2Sgxs(buildEnv env.ExecEnv, elfSgxPath, sgxsPath string, heapSize, stack
2130
}
2231

2332
cmd := exec.Command("ftxsgx-elf2sgxs", args...)
24-
if err := buildEnv.WrapCommand(cmd); err != nil {
25-
return err
33+
if err = buildEnv.WrapCommand(cmd); err != nil {
34+
return
35+
}
36+
if common.IsVerbose() {
37+
fmt.Println(cmd)
2638
}
2739
return cmd.Run()
2840
}

cmd/common/flags.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ var (
2222

2323
// FormatFlag specifies the command's output format (text/json).
2424
FormatFlag *flag.FlagSet
25+
26+
// VerboseFlag specifies the command's verbosity.
27+
VerboseFlag *flag.FlagSet
2528
)
2629

2730
// FormatType specifies the type of format for output of commands.
@@ -61,6 +64,7 @@ var (
6164
force bool
6265
answerYes bool
6366
outputFormat = FormatText
67+
verbose bool
6468
)
6569

6670
// GetHeight returns the user-selected block height.
@@ -84,6 +88,11 @@ func OutputFormat() FormatType {
8488
return outputFormat
8589
}
8690

91+
// IsVerbose returns verbose mode.
92+
func IsVerbose() bool {
93+
return verbose
94+
}
95+
8796
// GetActualHeight returns the user-selected block height if explicitly
8897
// specified, or the current latest height.
8998
func GetActualHeight(
@@ -113,4 +122,7 @@ func init() {
113122

114123
FormatFlag = flag.NewFlagSet("", flag.ContinueOnError)
115124
FormatFlag.Var(&outputFormat, "format", "output format ["+strings.Join([]string{string(FormatText), string(FormatJSON)}, ",")+"]")
125+
126+
VerboseFlag = flag.NewFlagSet("", flag.ContinueOnError)
127+
VerboseFlag.BoolVarP(&verbose, "verbose", "v", false, "verbose")
116128
}

cmd/rofl/build/build.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ var (
3333
outputFn string
3434
buildMode string
3535
offline bool
36-
noUpdate bool
3736
doVerify bool
3837
noDocker bool
3938
onlyValidate bool
@@ -134,12 +133,12 @@ var (
134133
return fmt.Errorf("unsupported app kind for SGX TEE: %s", manifest.Kind)
135134
}
136135

137-
sgxBuild(buildEnv, npa, manifest, deployment, bnd)
136+
sgxBuild(buildEnv, npa, manifest, deployment, bnd, doVerify)
138137
case buildRofl.TEETypeTDX:
139138
// TDX.
140139
switch manifest.Kind {
141140
case buildRofl.AppKindRaw:
142-
err = tdxBuildRaw(buildEnv, tmpDir, npa, manifest, deployment, bnd)
141+
err = tdxBuildRaw(buildEnv, tmpDir, npa, manifest, deployment, bnd, doVerify)
143142
case buildRofl.AppKindContainer:
144143
err = tdxBuildContainer(buildEnv, tmpDir, npa, manifest, deployment, bnd)
145144
}
@@ -242,10 +241,10 @@ var (
242241

243242
// Override the update manifest flag in case the policy does not exist.
244243
if deployment.Policy == nil {
245-
noUpdate = true
244+
roflCommon.NoUpdate = true
246245
}
247246

248-
switch noUpdate {
247+
switch roflCommon.NoUpdate {
249248
case true:
250249
// Ask the user to update the manifest manually (if the manifest has changed).
251250
if maps.Equal(buildEnclaves, latestManifestEnclaves) {
@@ -291,6 +290,11 @@ func setupBuildEnv(deployment *buildRofl.Deployment, npa *common.NPASelection) {
291290

292291
// Obtain and configure trust root.
293292
trustRoot, err := fetchTrustRoot(npa, deployment.TrustRoot)
293+
if deployment.Debug && err != nil {
294+
// Trust root is not mandatory for debug builds.
295+
fmt.Printf("WARNING: no trust root will be provided during compilation: %v\n", err)
296+
return
297+
}
294298
cobra.CheckErr(err)
295299
os.Setenv("ROFL_CONSENSUS_TRUST_ROOT", trustRoot)
296300
}
@@ -360,18 +364,14 @@ func init() {
360364
buildFlags := flag.NewFlagSet("", flag.ContinueOnError)
361365
buildFlags.BoolVar(&offline, "offline", false, "do not perform any operations requiring network access")
362366
buildFlags.StringVar(&outputFn, "output", "", "output bundle filename")
363-
buildFlags.BoolVar(&noUpdate, "no-update-manifest", false, "do not update the manifest")
364367
buildFlags.BoolVar(&doVerify, "verify", false, "verify build against manifest and on-chain state")
365368
buildFlags.BoolVar(&noDocker, "no-docker", false, "do not use the Dockerized builder")
366369
buildFlags.BoolVar(&onlyValidate, "only-validate", false, "validate without building")
367370

368371
buildFlags.AddFlagSet(roflCommon.DeploymentFlags)
369-
370-
// TODO: Remove when all the examples, demos and docs are updated.
371-
var dummy bool
372-
buildFlags.BoolVar(&dummy, "update-manifest", true, "not update the manifest")
373-
_ = buildFlags.MarkDeprecated("update-manifest", "the app manifest is now updated by default. Pass --no-update-manifest to prevent updating it.")
372+
buildFlags.AddFlagSet(roflCommon.NoUpdateFlag)
373+
buildFlags.AddFlagSet(common.VerboseFlag)
374+
buildFlags.AddFlagSet(common.ForceFlag)
374375

375376
Cmd.Flags().AddFlagSet(buildFlags)
376-
Cmd.Flags().AddFlagSet(common.ForceFlag)
377377
}

cmd/rofl/build/sgx.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,22 @@ func sgxBuild(
3232
manifest *buildRofl.Manifest,
3333
deployment *buildRofl.Deployment,
3434
bnd *bundle.Bundle,
35+
locked bool,
3536
) {
3637
fmt.Println("Building an SGX-based Rust ROFL application...")
3738

3839
features := sgxSetupBuildEnv(deployment, npa)
3940

4041
// First build for the default target.
4142
fmt.Println("Building ELF binary...")
42-
elfPath, err := cargo.Build(buildEnv, true, "x86_64-unknown-linux-gnu", features)
43+
elfPath, err := cargo.Build(buildEnv, true, locked, "x86_64-unknown-linux-gnu", features)
4344
if err != nil {
4445
cobra.CheckErr(fmt.Errorf("failed to build ELF binary: %w", err))
4546
}
4647

4748
// Then build for the SGX target.
4849
fmt.Println("Building SGXS binary...")
49-
elfSgxPath, err := cargo.Build(buildEnv, true, "x86_64-fortanix-unknown-sgx", nil)
50+
elfSgxPath, err := cargo.Build(buildEnv, true, locked, "x86_64-fortanix-unknown-sgx", nil)
5051
if err != nil {
5152
cobra.CheckErr(fmt.Errorf("failed to build SGXS binary: %w", err))
5253
}
@@ -109,9 +110,11 @@ func sgxBuild(
109110
sigName := "app.sig"
110111

111112
comp := bundle.Component{
112-
Kind: component.ROFL,
113-
Name: bnd.Manifest.Name,
114-
Executable: execName,
113+
Kind: component.ROFL,
114+
Name: bnd.Manifest.Name,
115+
ELF: &bundle.ELFMetadata{
116+
Executable: execName,
117+
},
115118
SGX: &bundle.SGXMetadata{
116119
Executable: sgxsName,
117120
Signature: sigName,

cmd/rofl/build/tdx.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ func tdxBuildRaw(
3636
manifest *buildRofl.Manifest,
3737
deployment *buildRofl.Deployment,
3838
bnd *bundle.Bundle,
39+
locked bool,
3940
) error {
4041
wantedArtifacts := tdxWantedArtifacts(manifest, buildRofl.LatestBasicArtifacts)
4142
artifacts := tdxFetchArtifacts(wantedArtifacts)
@@ -62,7 +63,7 @@ func tdxBuildRaw(
6263
}
6364

6465
fmt.Println("Building runtime binary...")
65-
initPath, err := cargo.Build(buildEnv, true, "", nil)
66+
initPath, err := cargo.Build(buildEnv, true, locked, "", nil)
6667
if err != nil {
6768
return fmt.Errorf("failed to build runtime binary: %w", err)
6869
}

cmd/rofl/common/flags.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,17 @@ var (
1313
// DeploymentFlags provide the deployment name.
1414
DeploymentFlags *flag.FlagSet
1515

16+
// NoUpdateFlag is the flag for disabling the rofl.yaml manifest file update.
17+
NoUpdateFlag *flag.FlagSet
18+
1619
// DeploymentName is the name of the ROFL app deployment.
1720
DeploymentName string
1821

1922
// WipeStorage enables wiping the machine storage on deployment/restart.
2023
WipeStorage bool
24+
25+
// NoUpdate disables updating the rofl.yaml manifest file.
26+
NoUpdate bool
2127
)
2228

2329
func init() {
@@ -26,4 +32,7 @@ func init() {
2632

2733
DeploymentFlags = flag.NewFlagSet("", flag.ContinueOnError)
2834
DeploymentFlags.StringVar(&DeploymentName, "deployment", buildRofl.DefaultDeploymentName, "deployment name")
35+
36+
NoUpdateFlag = flag.NewFlagSet("", flag.ContinueOnError)
37+
NoUpdateFlag.BoolVar(&NoUpdate, "no-update-manifest", false, "do not update the manifest")
2938
}

cmd/rofl/mgmt.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,10 @@ var (
279279
// Update the manifest with the given enclave identities, overwriting existing ones.
280280
deployment.AppID = appID.String()
281281

282-
if err = manifest.Save(); err != nil {
283-
cobra.CheckErr(fmt.Errorf("failed to update manifest: %w", err))
282+
if !roflCommon.NoUpdate {
283+
if err = manifest.Save(); err != nil {
284+
cobra.CheckErr(fmt.Errorf("failed to update manifest: %w", err))
285+
}
284286
}
285287

286288
fmt.Printf("Run `oasis rofl build` to build your ROFL app.\n")
@@ -735,6 +737,7 @@ func init() {
735737
createCmd.Flags().AddFlagSet(common.SelectorFlags)
736738
createCmd.Flags().AddFlagSet(common.RuntimeTxFlags)
737739
createCmd.Flags().AddFlagSet(roflCommon.DeploymentFlags)
740+
createCmd.Flags().AddFlagSet(roflCommon.NoUpdateFlag)
738741
createCmd.Flags().StringVar(&scheme, "scheme", "cn", "app ID generation scheme: creator+round+index [cri] or creator+nonce [cn]")
739742

740743
updateCmd.Flags().AddFlagSet(common.SelectorFlags)

0 commit comments

Comments
 (0)