Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(tonlibjson-sys): fix support for macos in build.rs #790

Merged
merged 7 commits into from
Apr 30, 2024

Conversation

mitinarseny
Copy link
Contributor

@mitinarseny mitinarseny commented Apr 22, 2024

Hey Team, thank you for these bindings! ❤️

I tried to use `tonlibjson-client and encountered an issue:

[dependepcies]
tonlibjson-client = { git = "https://github.com/getgems-io/ton-grpc.git" }

It didn't compile successfully on my MacBook M1:

cargo build output
cargo build
    Updating git repository `https://github.com/getgems-io/ton-grpc.git`
   Compiling tonlibjson-sys v0.3.1 (https://github.com/getgems-io/ton-grpc.git#f257c0da)
   Compiling tl_parser v0.1.0 (https://github.com/getgems-io/ton-grpc.git#f257c0da)
   Compiling tonlibjson-client v0.17.2 (https://github.com/getgems-io/ton-grpc.git#f257c0da)
error: failed to run custom build command for `tonlibjson-sys v0.3.1 (https://github.com/getgems-io/ton-grpc.git#f257c0da)`

Caused by:
  process didn't exit successfully: `/dev/project/target/debug/build/tonlibjson-sys-1480e5ed93844183/build-script-build` (exit status: 101)
  --- stdout
  cargo:rerun-if-env-changed=OPENSSL_NO_PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG_aarch64-apple-darwin
  cargo:rerun-if-env-changed=PKG_CONFIG_aarch64_apple_darwin
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG
  cargo:rerun-if-env-changed=OPENSSL_STATIC
  cargo:rerun-if-env-changed=OPENSSL_DYNAMIC
  cargo:rerun-if-env-changed=PKG_CONFIG_ALL_STATIC
  cargo:rerun-if-env-changed=PKG_CONFIG_ALL_DYNAMIC
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH_aarch64-apple-darwin
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH_aarch64_apple_darwin
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_PATH
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_aarch64-apple-darwin
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_aarch64_apple_darwin
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_LIBDIR
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_aarch64-apple-darwin
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_aarch64_apple_darwin
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_SYSROOT_DIR
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR
  cargo:rerun-if-env-changed=OPENSSL_STATIC
  cargo:rerun-if-env-changed=OPENSSL_DYNAMIC
  cargo:rerun-if-env-changed=PKG_CONFIG_ALL_STATIC
  cargo:rerun-if-env-changed=PKG_CONFIG_ALL_DYNAMIC
  cargo:rustc-link-search=native=/opt/homebrew/Cellar/openssl@3/3.3.0
  cargo:rustc-link-lib=ssl
  cargo:rustc-link-lib=crypto
  cargo:rerun-if-env-changed=PKG_CONFIG_aarch64-apple-darwin
  cargo:rerun-if-env-changed=PKG_CONFIG_aarch64_apple_darwin
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG
  cargo:rerun-if-env-changed=OPENSSL_STATIC
  cargo:rerun-if-env-changed=OPENSSL_DYNAMIC
  cargo:rerun-if-env-changed=PKG_CONFIG_ALL_STATIC
  cargo:rerun-if-env-changed=PKG_CONFIG_ALL_DYNAMIC
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH_aarch64-apple-darwin
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH_aarch64_apple_darwin
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_PATH
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_aarch64-apple-darwin
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_aarch64_apple_darwin
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_LIBDIR
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_aarch64-apple-darwin
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_aarch64_apple_darwin
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_SYSROOT_DIR
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR
  cargo:rustc-link-lib=static=c++
  cargo:rustc-link-search=native=/opt/homebrew/Cellar/openssl@3/3.3.0
  cargo:rustc-link-lib=static=crypto
  cargo:rustc-link-lib=static=ssl
  cargo:rustc-link-lib=static=sodium
  cargo:rustc-link-lib=static=secp256k1
  CMAKE_TOOLCHAIN_FILE_aarch64-apple-darwin = None
  CMAKE_TOOLCHAIN_FILE_aarch64_apple_darwin = None
  HOST_CMAKE_TOOLCHAIN_FILE = None
  CMAKE_TOOLCHAIN_FILE = None
  CMAKE_GENERATOR_aarch64-apple-darwin = None
  CMAKE_GENERATOR_aarch64_apple_darwin = None
  HOST_CMAKE_GENERATOR = None
  CMAKE_GENERATOR = None
  CMAKE_PREFIX_PATH_aarch64-apple-darwin = None
  CMAKE_PREFIX_PATH_aarch64_apple_darwin = None
  HOST_CMAKE_PREFIX_PATH = None
  CMAKE_PREFIX_PATH = None
  CMAKE_aarch64-apple-darwin = None
  CMAKE_aarch64_apple_darwin = None
  HOST_CMAKE = None
  CMAKE = None
  running: cd "/dev/project/target/debug/build/tonlibjson-sys-84f116fed36e0b68/out/build" && CMAKE_PREFIX_PATH="" "cmake" "/root/.cargo/git/checkouts/ton-grpc-8931e6ba334d2bde/f257c0d/tonlibjson-sys/ton-testnet" "-DCMAKE_OSX_ARCHITECTURES=arm64" "-DTON_ONLY_TONLIB=ON" "-DCMAKE_C_COMPILER=clang" "-DCMAKE_CXX_COMPILER=clang++" "-DCMAKE_CXX_STANDARD=14" "-DBUILD_SHARED_LIBS=OFF" "-DSODIUM_USE_STATIC_LIBS=OFF" "-DPORTABLE=ON" "-DTON_ARCH=x86-64" "-DCMAKE_SYSTEM_NAME=Darwin" "-DCMAKE_SYSTEM_PROCESSOR=arm64" "-DCMAKE_INSTALL_PREFIX=/root/dev/project/target/debug/build/tonlibjson-sys-84f116fed36e0b68/out" "-DCMAKE_C_FLAGS= -ffunction-sections -fdata-sections -fPIC --target=arm64-apple-darwin -mmacosx-version-min=10.11 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk" "-DCMAKE_CXX_FLAGS= -std=c++14 -stdlib=libc++ -ffunction-sections -fdata-sections -fPIC --target=arm64-apple-darwin -mmacosx-version-min=10.11 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk" "-DCMAKE_ASM_FLAGS= -ffunction-sections -fdata-sections -fPIC --target=arm64-apple-darwin -mmacosx-version-min=10.11 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk" "-DCMAKE_ASM_COMPILER=/usr/bin/cc" "-DCMAKE_BUILD_TYPE=Debug"
  -- The C compiler identification is AppleClang 15.0.0.15000100
  -- The CXX compiler identification is AppleClang 15.0.0.15000100
  -- Detecting C compiler ABI info
  -- Detecting C compiler ABI info - done
  -- Check for working C compiler: /usr/bin/clang - skipped
  -- Detecting C compile features
  -- Detecting C compile features - done
  -- Detecting CXX compiler ABI info
  -- Detecting CXX compiler ABI info - done
  -- Check for working CXX compiler: /usr/bin/clang++ - skipped
  -- Detecting CXX compile features
  -- Detecting CXX compile features - done
  -- Performing Test CRC32C_HAVE_SSE42
  -- Performing Test CRC32C_HAVE_SSE42 - Failed
  -- Performing Test ROCKSDB_HAVE_SSE42
  -- Performing Test ROCKSDB_HAVE_SSE42 - Failed
  -- Performing Test CRC32C_HAVE_NO_DEPRECATED
  -- Performing Test CRC32C_HAVE_NO_DEPRECATED - Success
  -- Performing Test CRC32C_HAVE_NO_SIGN_COMPARE
  -- Performing Test CRC32C_HAVE_NO_SIGN_COMPARE - Success
  -- Performing Test CRC32C_HAVE_NO_UNUSED_PARAMETER
  -- Performing Test CRC32C_HAVE_NO_UNUSED_PARAMETER - Success
  -- Performing Test CRC32C_HAVE_NO_MISSING_FIELD_INITIALIZERS
  -- Performing Test CRC32C_HAVE_NO_MISSING_FIELD_INITIALIZERS - Success
  -- Performing Test HAVE_BUILTIN_PREFETCH
  -- Performing Test HAVE_BUILTIN_PREFETCH - Success
  -- Performing Test HAVE_MM_PREFETCH
  -- Performing Test HAVE_MM_PREFETCH - Failed
  -- Performing Test HAVE_ARM64_CRC32C
  -- Performing Test HAVE_ARM64_CRC32C - Success
  -- Performing Test HAVE_STRONG_GETAUXVAL
  -- Performing Test HAVE_STRONG_GETAUXVAL - Failed
  -- Performing Test HAVE_WEAK_GETAUXVAL
  -- Performing Test HAVE_WEAK_GETAUXVAL - Failed
  -- Could NOT find ccache
  -- Performing Test CMAKE_HAVE_LIBC_PTHREAD
  -- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
  -- Found Threads: TRUE  
  -- Found PkgConfig: /opt/homebrew/bin/pkg-config (found version "0.29.2") 
  -- Found ZLIB: /Library/Developer/CommandLineTools/SDKs/MacOSX14.2.sdk/usr/lib/libz.tbd (found version "1.2.12")  
  -- Performing Test COMPILER_OPT_ARCH_SUPPORTED
  -- Performing Test COMPILER_OPT_ARCH_SUPPORTED - Failed
  -- Performing Test HAVE_CXX_FLAG_WALL
  -- Performing Test HAVE_CXX_FLAG_WALL - Success
  -- Performing Test HAVE_CXX_FLAG_WEXTRA
  -- Performing Test HAVE_CXX_FLAG_WEXTRA - Success
  -- Performing Test HAVE_CXX_FLAG_WIMPLICIT_FALLTHROUGH_2
  -- Performing Test HAVE_CXX_FLAG_WIMPLICIT_FALLTHROUGH_2 - Failed
  -- Performing Test HAVE_CXX_FLAG_WPOINTER_ARITH
  -- Performing Test HAVE_CXX_FLAG_WPOINTER_ARITH - Success
  -- Performing Test HAVE_CXX_FLAG_WCAST_QUAL
  -- Performing Test HAVE_CXX_FLAG_WCAST_QUAL - Success
  -- Performing Test HAVE_CXX_FLAG_WSIGN_COMPARE
  -- Performing Test HAVE_CXX_FLAG_WSIGN_COMPARE - Success
  -- Performing Test HAVE_CXX_FLAG_WDUPLICATED_BRANCHES
  -- Performing Test HAVE_CXX_FLAG_WDUPLICATED_BRANCHES - Failed
  -- Performing Test HAVE_CXX_FLAG_WDUPLICATED_COND
  -- Performing Test HAVE_CXX_FLAG_WDUPLICATED_COND - Failed
  -- Performing Test HAVE_CXX_FLAG_WALLOC_ZERO
  -- Performing Test HAVE_CXX_FLAG_WALLOC_ZERO - Failed
  -- Performing Test HAVE_CXX_FLAG_WLOGICAL_OP
  -- Performing Test HAVE_CXX_FLAG_WLOGICAL_OP - Failed
  -- Performing Test HAVE_CXX_FLAG_WTAUTOLOGICAL_COMPARE
  -- Performing Test HAVE_CXX_FLAG_WTAUTOLOGICAL_COMPARE - Success
  -- Performing Test HAVE_CXX_FLAG_WVLA
  -- Performing Test HAVE_CXX_FLAG_WVLA - Success
  -- Performing Test HAVE_CXX_FLAG_WNON_VIRTUAL_DTOR
  -- Performing Test HAVE_CXX_FLAG_WNON_VIRTUAL_DTOR - Success
  -- Performing Test HAVE_CXX_FLAG_WUNUSED_PARAMETER
  -- Performing Test HAVE_CXX_FLAG_WUNUSED_PARAMETER - Success
  -- Performing Test HAVE_CXX_FLAG_WCONVERSION
  -- Performing Test HAVE_CXX_FLAG_WCONVERSION - Success
  -- Performing Test HAVE_CXX_FLAG_WSIGN_CONVERSION
  -- Performing Test HAVE_CXX_FLAG_WSIGN_CONVERSION - Success
  -- Performing Test HAVE_CXX_FLAG_QUNUSED_ARGUMENTS
  -- Performing Test HAVE_CXX_FLAG_QUNUSED_ARGUMENTS - Success
  -- Performing Test HAVE_CXX_FLAG_WUNUSED_PRIVATE_FIELD
  -- Performing Test HAVE_CXX_FLAG_WUNUSED_PRIVATE_FIELD - Success
  -- Performing Test HAVE_CXX_FLAG_WREDUNDANT_MOVE
  -- Performing Test HAVE_CXX_FLAG_WREDUNDANT_MOVE - Success
  -- Could NOT find LATEX (missing: LATEX_COMPILER) 
  -- Could NOT find LATEX (this is NOT an error)
  -- Found ZLIB: /Library/Developer/CommandLineTools/SDKs/MacOSX14.2.sdk/usr/include /Library/Developer/CommandLineTools/SDKs/MacOSX14.2.sdk/usr/lib/libz.tbd
  -- Found OpenSSL: /opt/homebrew/Cellar/openssl@3/3.3.0/lib/libcrypto.dylib (found version "3.3.0")  
  -- Checking for module 'liblz4'
  --   Found liblz4, version 1.9.4
  -- Found LZ4 lz4 /opt/homebrew/Cellar/lz4/1.9.4/include
  -- Performing Test GNU_READLINE_FOUND
  -- Performing Test GNU_READLINE_FOUND - Failed
  -- Could NOT find Readline (missing: READLINE_INCLUDE_DIR READLINE_LIBRARY) 
  -- Could NOT find Readline (this is NOT an error)
  -- Found Secp256k1: /opt/homebrew/lib/libsecp256k1.dylib
  -- Found Secp256k1: /opt/homebrew/include  
  -- Found Sodium: /opt/homebrew/Cellar/libsodium/1.0.19/lib/libsodium.dylib  
  -- Performing Test COMPILER_HAS_HIDDEN_VISIBILITY
  -- Performing Test COMPILER_HAS_HIDDEN_VISIBILITY - Success
  -- Performing Test COMPILER_HAS_HIDDEN_INLINE_VISIBILITY
  -- Performing Test COMPILER_HAS_HIDDEN_INLINE_VISIBILITY - Success
  -- Performing Test COMPILER_HAS_DEPRECATED_ATTR
  -- Performing Test COMPILER_HAS_DEPRECATED_ATTR - Success
  -- Configuring done (4.9s)

  --- stderr
  ton dir is ton-testnet
  Add crc32c
  CMake Deprecation Warning at third-party/crc32c/CMakeLists.txt:5 (cmake_minimum_required):
    Compatibility with CMake < 3.5 will be removed from a future version of
    CMake.

    Update the VERSION argument <min> value or use a ...<max> suffix to tell
    CMake that the project does not need compatibility with older versions.


  Add ton
  CMake Error at crypto/CMakeLists.txt:378 (add_library):
    Cannot find source file:

      /root/.cargo/git/checkouts/ton-grpc-8931e6ba334d2bde/f257c0d/tonlibjson-sys/ton-testnet/crypto/block/block-auto.cpp

    Tried extensions .c .C .c++ .cc .cpp .cxx .cu .mpp .m .M .mm .ixx .cppm
    .ccm .cxxm .c++m .h .hh .h++ .hm .hpp .hxx .in .txx .f .F .for .f77 .f90
    .f95 .f03 .hip .ispc


  CMake Error at crypto/CMakeLists.txt:378 (add_library):
    No SOURCES given to target: ton_block


  CMake Generate step failed.  Build files cannot be regenerated correctly.
  thread 'main' panicked at /root/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cmake-0.1.50/src/lib.rs:1098:5:

  command did not execute successfully, got: exit status: 1

  build script failed, must exit now
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Turns out that there are two issues:

  1. aarch64 is not supported by tonlibjson-sys/build.rs
  2. cmake::Config::use_cxx11() breaks code generation somehow, I didn't dig too deep, so it's still an open question for me. I removed it and it works 🤔

Here is a small fix for the build script to make it compile to native arch. It uses the same approach as in build-macos-portable.rs except for couple of unnecessary(?) dependencies.
Hope it helps!

@akostylev0
Copy link
Member

akostylev0 commented Apr 22, 2024

Hello, @mitinarseny! Thank you for your work!

It seems there is an issue with the build on x86-64 platforms. The CARGO_CFG_TARGET_ARCH is set to x86_64, but cmake expects x86-64. Could you please look into this? Fixing this might not resolve all issues, but it’s a necessary first step.

UPD: I'm also unsure if using native architecture is an option, as it will likely affect the binary's portability.

@akostylev0
Copy link
Member

Thanks again, I will fix regression in next PRs.

@akostylev0 akostylev0 merged commit 12efff3 into getgems-io:master Apr 30, 2024
0 of 3 checks passed
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.

2 participants