Skip to content

refactor: move C/C++ code into sgx/ - #1054

Merged
mbrandenburger merged 3 commits into
hyperledger:mainfrom
mbrandenburger:build/sgx-subtree
Nov 5, 2026
Merged

mbrandenburger merged 3 commits into
hyperledger:mainfrom
mbrandenburger:build/sgx-subtree

Conversation

@mbrandenburger

Copy link
Copy Markdown
Contributor

What this PR does / why we need it:
Since #1048 the C/C++ side is opt-in (FPC_CGO=1), but its code was spread across the tree: common/, ecc_enclave/, cmake/, the cgo files in ecc/ and internal/, the C++ samples, irb's chaincode and the shell integration suites. This PR moves all of it under one directory, sgx/, so the code that needs the SGX toolchain is in one place. No behavior changes.

From To
common/ (incl. the common/crypto/pdo submodule) sgx/common/
ecc_enclave/ sgx/ecc_enclave/
cmake/ sgx/cmake/
samples/chaincode/{auction,echo,kv-test}/ sgx/samples/chaincode/…
samples/demos/irb/chaincode/ sgx/samples/demos/irb/chaincode/ (irb's Go app and protos stay)
integration/*_test.sh, integration/{config,crashtest,client_sdk}/ sgx/integration/… (integration/go_chaincode/ stays)
internal/attestation/epid/pdo/ sgx/attestation/epid/pdo/
the real enclave (ecc/chaincode/enclave/{enclave,shim,logging_cgo,logging_go}.go) sgx/ecc/enclave/ (the mock stays)

What stays: ecc/, fabric/, protos/, irb's Go app, integration/go_chaincode/, and the PDO crypto in internal/crypto/ (its test is coupled to the shared crypto test table; only its #cgo paths change).

Which issue(s) this PR fixes:
Fixes #1041. Part of #1044.

Special notes for your reviewer:
Three commits, best reviewed one by one (please rebase-merge, so git log --follow works):

  1. Moves only. git mv, 167 files renamed with identical content, and the .gitmodules path that git updates. The tree does not build at this commit.
  2. The enclave split, the only code change. ecc/main.go picks the enclave through newEnclave() in two tagged files, ecc/enclave_cgo.go (fpc_cgo, the real one from sgx/ecc/enclave) and ecc/enclave_mock.go (!fpc_cgo, the mock). scripts/check-ecc-enclave.sh checks which one ecc uses with and without the tag.
  3. Path fixes. Makefiles (the top level keeps the old build order, with sgx/... in place of each moved part), CMake and script $ENV{FPC_PATH} paths, #cgo paths, the moved shell suites (one level deeper), Go filepath.Join paths and the moved utils import, the committed symlinks, Dockerfiles, irb, and docs.

How I checked the move is complete:

  • A scratch script greps every old path (anchored, so samples/chaincode/echo doesn't match echo-go), the Go filepath.Join segment form, Go imports of moved packages, and dangling symlinks. The remaining hits are not paths: the ecc_enclave component and logger name, make target names, and the linter and license excludes, which match as substrings and still work.
  • A fresh git clone --recursive populates sgx/common/crypto/pdo and builds.
  • Natively (Mac): go build/vet/test ./..., make build test checks, and the check-* scripts pass.

Left as they were, because changing them would change behavior: ecc/Makefile's clean removes enclave/ecc-enclave-{lib,include}, a path that never existed (the links are committed, so actually removing them would leave the tree dirty); sgx/ecc_enclave/CMakeLists.txt sets an unused DEPLOY_DIR.

Does this PR introduce a user-facing changes and/or breaks backward compatability?:
Yes, paths change. For out-of-tree C++ chaincode and scripts:

Old New
$FPC_PATH/cmake/ $FPC_PATH/sgx/cmake/
$FPC_PATH/ecc_enclave/ (e.g. enclave/CMakeLists-common-app-enclave.txt) $FPC_PATH/sgx/ecc_enclave/
$FPC_PATH/common/ $FPC_PATH/sgx/common/
$FPC_PATH/integration/config/ $FPC_PATH/sgx/integration/config/
$FPC_PATH/samples/chaincode/{auction,echo,kv-test}/ $FPC_PATH/sgx/samples/chaincode/…

Go: internal/attestation/epid/pdo (internal, so only used in this repo) is now sgx/attestation/epid/pdo, and the real enclave package ecc/chaincode/enclave is now sgx/ecc/enclave (ecc/chaincode/enclave keeps the mock). Existing build directories (_build) under the old paths have to be rebuilt.

@mbrandenburger mbrandenburger self-assigned this Nov 4, 2026
@mbrandenburger
mbrandenburger marked this pull request as ready for review November 4, 2026 19:42
@mbrandenburger
mbrandenburger requested a review from a team as a code owner November 4, 2026 19:42
Moves only, no content changes apart from the submodule path, which git
updates: the C/C++ code (common/, ecc_enclave/, cmake/), the C++ samples
and irb's chaincode, the shell integration suites, the cgo PDO verifier
and the real enclave go to sgx/.

The tree does not build at this commit; paths are fixed in the next two
commits. Kept separate so git log --follow works and the moves can be
reviewed on their own.

Signed-off-by: Marcus Brandenburger <bur@zurich.ibm.com>
The real (cgo) enclave now lives in sgx/ecc/enclave, the mock stays in
ecc/chaincode/enclave. ecc picks one through newEnclave(), in two tagged
files (fpc_cgo / !fpc_cgo). This is the only code change of the move.

ecc/Makefile now builds the ecc package (go build -o ecc .) instead of
main.go alone: naming a file makes go build only that file, so it would
skip the two tagged files and newEnclave would be undefined.

The moved cgo packages (sgx/ecc/enclave, sgx/attestation/epid/pdo) get
their #cgo paths into sgx/common; ercc and the attestation-api test app
import the PDO verifier from its new path. shim.go's include, which on
main pointed at a non-existent ecc/common, is now correct as it stands.

scripts/check-ecc-enclave.sh checks which enclave ecc uses with and
without fpc_cgo, that ecc/Makefile builds the package, and in the dev
container that ecc links libsgxcc.

Signed-off-by: Marcus Brandenburger <bur@zurich.ibm.com>
The paths that point into the moved code:
- the top-level Makefile builds sgx/common, sgx/ecc_enclave,
  sgx/samples and sgx/integration in the same order as before the move;
  new sgx/samples/Makefile and sgx/integration/Makefile, integration/
  keeps only the FPC-go suites
- TOP in every moved Makefile, the $ENV{FPC_PATH} paths in CMake and
  scripts, #cgo paths (internal/crypto/crypto_pdo.go stays in place)
- the moved shell suites are one level deeper; their config, chaincode
  and client SDK utils paths, also where Go builds them with
  filepath.Join and imports the utils package
- the committed symlinks (ecc-enclave-include/lib, integration/config/ias)
- ecc, Dockerfiles, .dockerignore, .gitignore, the external builder,
  irb (its chaincode moved, its Go app and protos did not)
- the peer's fpc-c external builder path in sgx/integration/config/core.yaml
- check-fpc-cgo.sh, the proto comments and the docs

Small changes made while touching these files: samples/chaincode/Makefile
drops its now redundant SUB_DIRS/TEST_DIRS, and two crashtest build files
get the SPDX header the license check asks for.

The old paths are kept where they are not paths: the ecc_enclave
component and logger name, make target names, and the substring
excludes of the linter and license scripts, which still match.

Signed-off-by: Marcus Brandenburger <bur@zurich.ibm.com>
@mbrandenburger
mbrandenburger merged commit f0bc06a into hyperledger:main Nov 5, 2026
7 checks passed
@mbrandenburger
mbrandenburger deleted the build/sgx-subtree branch November 5, 2026 16:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Move C/C++ code and cgo packages into sgx/

2 participants