@@ -45,21 +45,37 @@ func sgxBuild(
4545 cobra .CheckErr (fmt .Errorf ("failed to build ELF binary: %w" , err ))
4646 }
4747
48- // Then build for the SGX target.
49- fmt .Println ("Building SGXS binary..." )
50- elfSgxPath , err := cargo .Build (buildEnv , true , locked , "x86_64-fortanix-unknown-sgx" , nil )
51- if err != nil {
52- cobra .CheckErr (fmt .Errorf ("failed to build SGXS binary: %w" , err ))
53- }
48+ var sgxsPath string
49+ switch buildMode {
50+ case buildModeProduction :
51+ // Build proper SGX target.
52+ fmt .Println ("Building SGXS binary..." )
53+ elfSgxPath , err := cargo .Build (buildEnv , true , locked , "x86_64-fortanix-unknown-sgx" , nil )
54+ if err != nil {
55+ cobra .CheckErr (fmt .Errorf ("failed to build SGXS binary: %w" , err ))
56+ }
5457
55- sgxThreads := uint64 (32 )
56- sgxHeapSize := manifest .Resources .Memory * 1024 * 1024
57- sgxStackSize := uint64 (2 * 1024 * 1024 )
58+ sgxThreads := uint64 (32 )
59+ sgxHeapSize := manifest .Resources .Memory * 1024 * 1024
60+ sgxStackSize := uint64 (2 * 1024 * 1024 )
5861
59- sgxsPath := fmt .Sprintf ("%s.sgxs" , elfSgxPath )
60- err = sgxs .Elf2Sgxs (buildEnv , elfSgxPath , sgxsPath , sgxHeapSize , sgxStackSize , sgxThreads )
61- if err != nil {
62- cobra .CheckErr (fmt .Errorf ("failed to generate SGXS binary: %w" , err ))
62+ sgxsPath = fmt .Sprintf ("%s.sgxs" , elfSgxPath )
63+ err = sgxs .Elf2Sgxs (buildEnv , elfSgxPath , sgxsPath , sgxHeapSize , sgxStackSize , sgxThreads )
64+ if err != nil {
65+ cobra .CheckErr (fmt .Errorf ("failed to generate SGXS binary: %w" , err ))
66+ }
67+ case buildModeUnsafe :
68+ // Generate dummy SGXS file.
69+ fmt .Println ("Building dummy SGXS binary..." )
70+ tmpFile , err := os .CreateTemp ("" , "app.sgxs" )
71+ if err != nil {
72+ cobra .CheckErr (fmt .Errorf ("failed to create dummy SGXS file: %w" , err ))
73+ }
74+ if _ , err := tmpFile .Write ([]byte ("dummy\n " )); err != nil {
75+ cobra .CheckErr (fmt .Errorf ("failed to write to dummy SGXS file: %w" , err ))
76+ }
77+ tmpFile .Close ()
78+ sgxsPath = tmpFile .Name ()
6379 }
6480
6581 // Compute MRENCLAVE.
0 commit comments