Posts

Showing posts with the label cross-compilation

Scaling number of supported platforms. Cross compilation of the rust code with bazel. Part 5

Image
  This is the 5th part of Basel cross-compilation series. Previous posts: What? Do I really need to configure C++ compiler to compile rust? Compilation from macOS(Intel) to linux x86_64 finaly works.  Cross compilation for ARM v7.  Fetching toolchains at build time.   All the build files in the previous steps looked pretty much the same, the only differences were: URLs exec architecture target architecture some compiler flags (like paths) Of cause we don't want to support a separate build file for every host and target combination. The way around it maybe to generate it from the template. The easiest way would be to use string formatting int the *.bzl file. So we create `toolchains/cpp_toolchains.bzl`, and store the BUILD file content in the variable there: BUILD_FILE_TEMPLATE = """ load("@bazel_tools//tools/cpp:unix_cc_toolchain_config.bzl", "cc_toolchain_config") load...

Fetching toolchains at build time. Cross compilation of the rust code with bazel. Part 4

Adding toolchain binaries directly int the repository isn't actually a good idea: the repository is getting bigger and bigger. It takes a while to check it out even in a the case, you want just to take a look. So to add new toolchain, we will try to fetch it on "runtime", i.e. when we execute some bazel command. Today we will add a toolchain, that compiles aarch64 binaries from macOS. For fetching something from internet, bazel has an "http_archive" rule, we have already used it to fetch the rust_rules in the Part 1. We can fetch arbitrary archives with this rule, in our case the toolchain tarball. http_archive ( name = "aarch64-unknown-linux-musl" , sha256 = "4fbe95500c327828b437f380bb15851e9a8126cf95180fbf15b76b78e0322ae3" , urls = [ "https://github.com/messense/homebrew-macos-cross-toolchains/releases/download/v11.2.0-1/aarch64-unknown-linux-musl-x86_64-darwin.tar.gz" ], strip_prefix = "aarch64-unknown-linux-...

Cross compilation for ARM v7. Cross compilation of the rust code with bazel. Part 3.

This is the third part of the series "Cross compilation of rust with bazel". Previous topics: What? Do I really need to configure C++ compiler to compile rust? Cross compilation of the rust code with bazel. Part 1. Compilation from macOS(Intel) to linux x86_64 finaly works. Cross compilation of the rust code with bazel. Part 2.   Next challenge is to cross-compile for armv7. This part we did together with my colleague Dima and we did it on linux. First thing, that we need is to add the target platform into our root BUILD.bazel platform ( name = "armv7-linux-musleabihf" , constraint_values = [ "@platforms//cpu:armv7" , "@platforms//os:linux" , ], ) And rust toolchain for the new target in the WORKSPACE file: rust_register_toolchains ( edition = "2021" , extra_target_triples = [ "x86_64-unknown-linux-musl" , "armv7-unknown-linux-musleabihf" , # NEW ], ) And as we remember from the part 1 ,...