Fix and extend cross compilation with static builds

[?]
Mar 22, 2023, 3:38 PM
ZFMPQAFVZP6NC6VZK3YAKIMSS5NYOV47HITL5TQ2YCD3KRCZWREQC

Dependencies

Change contents

  • replacement in src/CMakeLists.txt at line 5
    [4.87][4.87:115]()
    find_package(CURL REQUIRED)
    [4.87]
    [4.115]
    include(FindPkgConfig)
    pkg_search_module(CURL REQUIRED libcurl)
  • replacement in src/CMakeLists.txt at line 10
    [4.153][4.153:209]()
    target_link_libraries(wttr-delft PRIVATE CURL::libcurl)
    [4.153]
    [4.209]
    target_link_libraries(wttr-delft ${CURL_LIBRARIES})
    target_include_directories(wttr-delft PUBLIC ${CURL_INCLUDE_DIRS})
    target_compile_options(wttr-delft PUBLIC ${CURL_CFLAGS_OTHER})
  • replacement in README.md at line 26
    [2.616][2.616:754]()
    * [04-cmake-and-cross](04-cmake-and-cross/demo.sh): Building packages that use CMake, and cross-compile them for different architectures.
    [2.616]
    [4.473]
    * [04-cmake-and-cross](04-cmake-and-cross/demo.sh): Building packages that use CMake, and cross-compile them for different architectures and static executables. Doing the same with emulation.
  • edit in 04-cmake-and-cross/wttr-delft.nix at line 4
    [4.361]
    [4.361]
    , pkgconfig
  • replacement in 04-cmake-and-cross/wttr-delft.nix at line 14
    [4.235][4.235:268]()
    nativeBuildInputs = [ cmake ];
    [4.235]
    [4.597]
    nativeBuildInputs = [ cmake pkgconfig ];
  • replacement in 04-cmake-and-cross/flake.nix at line 27
    [3.93][4.701:747](),[4.4591][4.701:747](),[4.747][3.94:277]()
    packages.default = pkgs.wttr-delft;
    # But the package set also has a pkgsCross set, and we can select our package from one of its contents
    packages.cross-riscv64 = pkgs.pkgsCross.riscv64.wttr-delft;
    [3.93]
    [4.4895]
    packages = {
    default = pkgs.wttr-delft;
    # But the package set also has a pkgsCross set, and we can select our package from one of its contents
    cross-riscv64 = pkgs.pkgsCross.riscv64.wttr-delft;
    static = pkgs.pkgsCross.musl64.pkgsStatic.wttr-delft;
    cross-aarch64-static = pkgs.pkgsCross.aarch64-multiplatform.pkgsStatic.wttr-delft;
    };
  • edit in 04-cmake-and-cross/demo.sh at line 24
    [4.1421][4.1421:1485]()
    # x nix build "${dir}" -L --rebuild
    h Checking out the closure
  • edit in 04-cmake-and-cross/demo.sh at line 25
    [4.1486][4.1486:1590]()
    n The \'closure\' is the full set of all the \(runtime\) dependencies:
    x nix path-info -sSrh ./result
  • replacement in 04-cmake-and-cross/demo.sh at line 34
    [3.638][3.638:673]()
    x nix build "${dir}#cross-riscv64"
    [3.638]
    [3.673]
    x nix build "${dir}#cross-riscv64" -L
  • edit in 04-cmake-and-cross/demo.sh at line 38
    [3.752]
    [3.752]
    h Static executables
    , We can also cross compile a static build:
    x nix build "${dir}#static" -L
    , And this is indeed a static binary:
    x "${file_cmd}" ./result/bin/wttr-delft
    x ls -lh ./result/bin/wttr-delft
    h Everything together
    , Static cross compiled for aarch64-linux - you can copy this executable and run it on a Raspberry Pi!
    x nix build "${dir}#cross-aarch64-static" -L
    x "${file_cmd}" ./result/bin/wttr-delft
    x ls -lh ./result/bin/wttr-delft
  • replacement in 04-cmake-and-cross/demo.sh at line 61
    [4.187][4.187:189]()
    p
    [4.2139]
    , And we can actually run it as well!
    x ./result/bin/wttr-delft