1- package rofl
1+ package build
22
33import (
4- "context"
54 "crypto/rand"
65 "crypto/rsa"
76 "fmt"
@@ -17,39 +16,21 @@ import (
1716 "github.com/oasisprotocol/oasis-core/go/common/sgx"
1817 "github.com/oasisprotocol/oasis-core/go/common/sgx/sigstruct"
1918 "github.com/oasisprotocol/oasis-core/go/common/version"
20- consensus "github.com/oasisprotocol/oasis-core/go/consensus/api"
2119 "github.com/oasisprotocol/oasis-core/go/runtime/bundle"
2220 "github.com/oasisprotocol/oasis-core/go/runtime/bundle/component"
23- "github.com/oasisprotocol/oasis-sdk/client-sdk/go/connection"
2421
2522 "github.com/oasisprotocol/cli/build/cargo"
2623 "github.com/oasisprotocol/cli/build/sgxs"
2724 "github.com/oasisprotocol/cli/cmd/common"
2825 cliConfig "github.com/oasisprotocol/cli/config"
2926)
3027
31- // Build modes.
32- const (
33- buildModeProduction = "production"
34- buildModeUnsafe = "unsafe"
35- buildModeAuto = "auto"
36- )
37-
3828var (
3929 sgxHeapSize uint64
4030 sgxStackSize uint64
4131 sgxThreads uint64
4232
43- outputFn string
44- buildMode string
45- offline bool
46-
47- buildCmd = & cobra.Command {
48- Use : "build" ,
49- Short : "Build a ROFL application" ,
50- }
51-
52- buildSgxCmd = & cobra.Command {
33+ sgxCmd = & cobra.Command {
5334 Use : "sgx" ,
5435 Short : "Build an SGX-based Rust ROFL application" ,
5536 Args : cobra .NoArgs ,
6546
6647 fmt .Println ("Building an SGX-based Rust ROFL application..." )
6748
68- // Configure build mode. In case auto is selected and not offline, query the network.
69- // If autodetection fails, default to production mode.
70- switch {
71- case buildMode == buildModeAuto && ! offline :
72- ctx := context .Background ()
73- conn , err := connection .Connect (ctx , npa .Network )
74- if err != nil {
75- cobra .CheckErr (fmt .Errorf ("unable to autodetect build mode, please provide --mode flag manually: failed to connect to GRPC endpoint: %v" , err ))
76- }
77-
78- params , err := conn .Consensus ().Registry ().ConsensusParameters (ctx , consensus .HeightLatest )
79- if err != nil {
80- cobra .CheckErr (fmt .Errorf ("unable to autodetect build mode, please provide --mode flag manually: failed to get consensus parameters: %v" , err ))
81- }
82-
83- if params .DebugAllowTestRuntimes {
84- buildMode = buildModeUnsafe
85- }
86- default :
87- }
49+ detectBuildMode (npa )
8850 features := sgxSetupBuildEnv ()
8951
9052 // Obtain package metadata.
@@ -333,15 +295,7 @@ func init() {
333295 sgxFlags .Uint64Var (& sgxHeapSize , "sgx-heap-size" , 512 * 1024 * 1024 , "SGX enclave heap size" )
334296 sgxFlags .Uint64Var (& sgxStackSize , "sgx-stack-size" , 2 * 1024 * 1024 , "SGX enclave stack size" )
335297 sgxFlags .Uint64Var (& sgxThreads , "sgx-threads" , 32 , "SGX enclave maximum number of threads" )
336- sgxFlags .StringVar (& outputFn , "output" , "" , "output bundle filename" )
337-
338- globalFlags := flag .NewFlagSet ("" , flag .ContinueOnError )
339- globalFlags .StringVar (& buildMode , "mode" , "auto" , "build mode [production, unsafe, auto]" )
340- globalFlags .BoolVar (& offline , "offline" , false , "do not perform any operations requiring network access" )
341-
342- buildSgxCmd .Flags ().AddFlagSet (common .SelectorNPFlags )
343- buildSgxCmd .Flags ().AddFlagSet (sgxFlags )
344298
345- buildCmd . PersistentFlags ().AddFlagSet (globalFlags )
346- buildCmd . AddCommand ( buildSgxCmd )
299+ sgxCmd . Flags ().AddFlagSet (common . SelectorNPFlags )
300+ sgxCmd . Flags (). AddFlagSet ( sgxFlags )
347301}
0 commit comments