immunant / c2rust

Migrate C code to Rust
https://c2rust.com/
Other
4.02k stars 243 forks source link

support offline build #356

Open milahu opened 2 years ago

milahu commented 2 years ago

somewhere in the middle of the build process, c2rust-ast-exporter is trying to download tinycbor v0.5.3

for nixos/nix, the build must be completely offline (nixpkgs provides tinycbor v0.5.4 ...)

error: failed to run custom build command for `c2rust-ast-exporter v0.15.0 (/build/c2rust/c2rust-ast-exporter)`

Caused by:
  process didn't exit successfully: `/build/c2rust/target/debug/build/c2rust-ast-exporter-debe5ea54505972d/build-script-build` (exit code: 101)
--- stdout
running: "cmake" "cmake" "/build/c2rust/c2rust-ast-exporter/src" ...
...
-- Configuring done
-- Generating done
-- Build files have been written to: /build/c2rust/target/x86_64-unknown-linux-gnu/debug/build/c2rust-ast-exporter-e528e0a9cbfd1393/out/build
running: "cmake" "cmake" "--build" "." "--target" "clangAstExporter" "--config" "Debug" "--"
[  8%] Creating directories for 'tinycbor_build'
[ 16%] Performing download step (download, verify and extract) for 'tinycbor_build'
-- Downloading...
...
CMake Error at tinycbor_build-stamp/download-tinycbor_build.cmake:170 (message):
  Each download failed!

    error: downloading 'https://github.com/intel/tinycbor/archive/v0.5.3.tar.gz' failed
          status_code: 6
          status_string: "Couldn't resolve host name"
          log:
          --- LOG BEGIN ---
          Could not resolve host: github.com
# c2rust/c2rust-ast-exporter/src/CMakeLists.txt

set(TINYCBOR_URL "https://github.com/intel/tinycbor/archive/v0.5.3.tar.gz"
    CACHE STRING "tinycbor download URL")
set(TINYCBOR_MD5 "2cd3af70d8749a7ddd5a8d04d09ea8f6" CACHE STRING "tinycbor archive md5 sum")
set(TINYCBOR_PREFIX "${CMAKE_BINARY_DIR}/tinycbor" CACHE STRING "tinycbor install prefix")

include(ExternalProject)
ExternalProject_Add(tinycbor_build
            PREFIX ${TINYCBOR_PREFIX}
            INSTALL_DIR ${CMAKE_BINARY_DIR}
            URL ${TINYCBOR_URL}
            URL_HASH MD5=${TINYCBOR_MD5}
            CONFIGURE_COMMAND ""
            BUILD_COMMAND make --quiet prefix=<INSTALL_DIR> CFLAGS=-fPIC
            INSTALL_COMMAND make --quiet prefix=<INSTALL_DIR> install            
            BUILD_IN_SOURCE 1
            BUILD_BYPRODUCTS ${CMAKE_BINARY_DIR}/lib/libtinycbor.a
)
milahu commented 2 years ago

now using

# find tinycbor with pkgconfig
include(FindPkgConfig)
pkg_search_module(tinycbor_build REQUIRED tinycbor-0.5.3 tinycbor>=0.5.3)
include_directories(${tinycbor_build_INCLUDE_DIRS})
add_library(tinycbor STATIC IMPORTED)
set_target_properties(tinycbor PROPERTIES IMPORTED_LOCATION ${tinycbor_build_LINK_LIBRARIES})
add_dependencies(tinycbor tinycbor_build)
# debug
message("tinycbor_build_INCLUDE_DIRS = ${tinycbor_build_INCLUDE_DIRS}")
message("tinycbor_build_LINK_LIBRARIES = ${tinycbor_build_LINK_LIBRARIES}")
message("tinycbor_build_LIBRARIES = ${tinycbor_build_LIBRARIES}")
# tinycbor_build_INCLUDE_DIRS = /nix/store/h1xb2ri81rmc0bmai5x8g4fs1ddbmggs-tinycbor-0.6.0/include/tinycbor
# tinycbor_build_LINK_LIBRARIES = /nix/store/h1xb2ri81rmc0bmai5x8g4fs1ddbmggs-tinycbor-0.6.0/lib/libtinycbor.a
# tinycbor_build_LIBRARIES = tinycbor
kkysen commented 2 years ago

@milahu, we might try to fix this now, since this also breaks docs.rs/c2rust (see https://github.com/immunant/c2rust/issues/470).