Skip to content

build: mac, use native clang as default compiler#322

Merged
miketout merged 68 commits intomiketout:devfrom
DeckerSU:patch-verus-build-mac
Nov 2, 2024
Merged

build: mac, use native clang as default compiler#322
miketout merged 68 commits intomiketout:devfrom
DeckerSU:patch-verus-build-mac

Conversation

@DeckerSU
Copy link
Copy Markdown

@DeckerSU DeckerSU commented Nov 2, 2024

This PR attempts to switch the macOS build from the outdated gcc@8 to the native clang. However, building with clang requires extensive changes in the source code to resolve various ambiguities and other issues. Additionally, some fixes reveal existing hidden errors in the code, such as in this commit, where exportOutNum was mistakenly declared as a bool instead of an int in PreCheckAcceptedOrEarnedNotarization.

Every commit needs to be carefully reviewed, and the entire build should pass all internal tests, including syncing from scratch, before this PR is accepted.

p.s. Also, please note that this version has been tested on macOS Monterey 12.6.1 with Xcode 13.2.1 and Apple clang version 13.0.0 (clang-1300.0.29.30). Other macOS versions or newer Xcode releases are likely to fail to build the project. I plan to address these issues after all introduced changes in this PR are accepted. This PR is the first step toward making the macOS build cleaner, more correct, and more maintainable.

Asherda and others added 30 commits June 14, 2024 08:29
without that fix clang gives an error:

./mmr.h:143:35: error: overloaded operator >> has higher precedence than comparison operator [-Werror,-Woverloaded-shift-op-parentheses]
        assert(work << 128 >> 128 == work && stake << 128 >> 128 == stake);
               ~~~~~~~~~~~~~~~~~~ ^  ~~~~
./pbaas/vdxf.h:817:24: error: no matching constructor for initialization of 'uint256'
                salt = uint256(std::vector<unsigned char>(data.end() - sizeof(uint256)), data.end());
                       ^       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./uint256.h:119:5: note: candidate constructor not viable: requires single argument 'b', but 2 arguments were provided
    uint256(const base_blob<256>& b) : base_blob<256>(b) {}

It was accidentally separated data.end() - sizeof(uint256) and data.end() into two arguments instead of passing them as a range.

The fix creates a std::vector<unsigned char> from the range [data.end() - sizeof(uint256), data.end()).

The single std::vector is then passed to the uint256 constructor that takes a const std::vector<unsigned char>&, matching the expected constructor.
TODO: reconsider all of these flags
Manual invocation of internal functions like __tls_init() is not recommended and is typically unnecessary.
avoid this error:

src/tcp_address.cpp:132:12: error: 'sprintf' is deprecated: This function is provided for compatibility reasons only.  Due to security concerns inherent in the design of sprintf(3), it is highly recommended that you use snprintf(3) instead. [-Werror,-Wdeprecated-declarations]
    pos += sprintf (pos, "%d", ntohs (port_));
           ^

when building on with Apple clang version 14.0.3 (clang-1403.0.22.14.1)
older versions of rust will give error like this on modern osx and xcode:

b6f6b59b6a29ec3a.rlib(rust.metadata.bin), archive member 'rust.metadata.bin' with length 23385156 is not mach-o or llvm bitcode file '/Users/builder/verus-mac-build/depends/x86_64-apple-darwin22.5.0/native/lib/rustlib/x86_64-apple-darwin/lib/libcore-b6f6b59b6a29ec3a.rlib'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
@DeckerSU
Copy link
Copy Markdown
Author

DeckerSU commented Nov 2, 2024

Build of last commit is tested on:

ProductName:		macOS
ProductVersion:		13.4
BuildVersion:		22F66
Xcode 14.3.1
Build version 14E300c
Apple clang version 14.0.3 (clang-1403.0.22.14.1)
Target: x86_64-apple-darwin22.5.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

@miketout miketout merged commit e173523 into miketout:dev Nov 2, 2024
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.

3 participants