Fix macOS build hangs and test compilation errors #844
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem 1: Build hangs at 256/258 CMake targets on macOS
Issue
When running
just monero_syson macOS, the build would consistently hang at CMake build progress[256/258], preventing the build from completing. This occurred during the final linking phase of large static libraries (wallet_apiandwallet).Root Cause
The build was using full CPU parallelism (
num_cpus::get()= 8 jobs on typical Macs) for CMake builds. During the final linking stage, multiple large static libraries were being linked in parallel, causing:ld) can deadlock when multiple large static library links compete for the same dependency libraries or file system resourceswallet_apiandwalletlibraries) were waiting for shared dependencies to finish linkingSolution
-j2) on macOSMONERO_PARALLEL_LINK_JOBS=1on macOS to ensure only one linking job runs at a timeChanges:
monero-sys/build.rs: Added macOS-specific logic to reduce-jfromnum_cpus::get()to2monero-sys/build.rs: AddedMONERO_PARALLEL_LINK_JOBS=1CMake define for macOS targetsTrade-off: Builds will be slower on macOS (2 jobs instead of 8), but they will complete successfully without hanging. Other platforms continue to use full parallelism.
Problem 2: Test compilation failures due to Scalar type mismatches
Issue
Running
cargo nextest runfailed with compilation errors in test code:swap-machine/src/lib.rs:98:Scalar::one()doesn't exist incurve25519-dalekv4.1.3swap-core/src/monero/primitives.rs:728,736: Type mismatch betweencurve25519_dalek::Scalarandcurve25519_dalek_ng::scalar::Scalarwhen callingmonero::PrivateKey::from_scalar()swap-machine/src/lib.rs:96: Type mismatch -xmr_locked()expectsTransferProofMaybeWithTxKeybut was receivingTransferProofRoot Cause
The codebase uses two different
curve25519-dalekcrates:curve25519-dalek(v4.1.3) - used inswap-coreandswap-machinecurve25519-dalek-ng(v4.1.1) - used internally by themonerocrateThese are distinct types that cannot be directly converted. Additionally:
Scalar::one()was removed in newer versions ofcurve25519-dalekmonero::PrivateKey::from_scalar()expectscurve25519_dalek_ng::scalar::Scalar, notcurve25519_dalek::ScalarTransferProofMaybeWithTxKeyinstead ofTransferProofSolution
swap-machine/src/lib.rs: ReplacedScalar::one()usage with constructing a dummy private key from fixed bytes usingPrivateKey::from_slice(), and added.into()to convertTransferProoftoTransferProofMaybeWithTxKeyswap-core/src/monero/primitives.rs: Changed frommonero::PrivateKey::from_scalar(Scalar::random(...))tomonero::PrivateKey::from_slice(scalar.as_bytes()), following the existing pattern inPrivateViewKey::new_random()Changes:
swap-machine/src/lib.rs: Construct dummy private key from bytes instead of usingScalar::one(), and convertTransferProoftoTransferProofMaybeWithTxKeyusing.into()swap-core/src/monero/primitives.rs: Usefrom_slice()with scalar bytes instead offrom_scalar()to avoid type mismatchThis approach avoids mixing the two
Scalartypes by working with raw bytes, which both crates can handle.