Build rust-skia via buildRustPackage


At the moment, I am trying to build a rust package using buildRustPackage function where that package depends on GitHub - rust-skia/rust-skia: Safe Skia Bindings for Rust. The rust-skia has some of it’s dependencies as git submodules, along with the skia (the original underlying project) is tend to fetch its dependencies during the build. I managed to do all the heavy lifting and pre-fetch all the dependencies as fixed-output derivations and finally get the whole project built on Darwin, both, x86 and aarch64.

However, I can’t build it for the Linux/x86. the problematic part is that the when the rust-skia is trying to build skia I am getting the error like:

g++: error: unrecognized command-line option '--target=x86_64-unknown-linux-gnu'
  ninja: build stopped: subcommand failed.
  --- stderr
  thread 'main' panicked at '`ninja` returned an error, please check the output for details.', /build/cargo-vendor-dir/skia-bindings-0.43.0/build_support/skia/
  stack backtrace:
     0: std::panicking::begin_panic
     1: build_script_build::build_support::skia::config::build_skia
     2: build_script_build::build_support::skia::config::build
     3: build_script_build::build_from_source
     4: build_script_build::main
     5: core::ops::function::FnOnce::call_once
  note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

(I cut the whole c++ invocation for convenience, happy to provide mode details if needed)
I use gcc 11 that comes from the stdenv.

Is there something obvious I am missing here? Any help is much appreciated.

For the future discourse travelers. I figured it out, skia is not supposed to be built via gcc, but via clang. I switched the stdenv for the buildRustPackage to use the right one via:

  pkgs' = pkgs.extend (self: super: {
    makeRustPlatform = super.makeRustPlatform.override {
      stdenv = super.llvmPackages_12.stdenv;
in with pkgs'; buildRustPackage {
  # ... 
  nativeBuildInputs = [
  ] ++ lib.optionals stdenv.isLinux [
  ] ++ lib.optionals stdenv.isDarwin (with darwin.apple_sdk.frameworks; [

I also included rustPlatform.bindgenHook otherwise, the build will fail because the skia-bindings uses the bindgen crate.