Fix WASI target by getting rid of CC

This commit is contained in:
oxalica 2022-04-09 03:22:13 +08:00
parent f7d4a3aabe
commit 44801306a2
4 changed files with 27 additions and 18 deletions

View File

@ -151,10 +151,7 @@ jobs:
strategy:
fail-fast: false
matrix:
# `wasm32-wasi-stage-final-gcc` is currently broken.
# https://github.com/oxalica/rust-overlay/runs/5247844387
# example: [cross-aarch64, cross-wasi, cross-mingw]
example: [cross-aarch64, cross-mingw]
example: [cross-aarch64, cross-wasi, cross-mingw]
steps:
- name: Checkout

View File

@ -7,8 +7,9 @@
};
overlays = [ (import ../..) ];
}).callPackage (
{ mkShell, stdenv, rust-bin, wasmtime }:
mkShell {
# We don't need WASI C compiler from nixpkgs, so use `mkShellNoCC`.
{ mkShellNoCC, stdenv, rust-bin, wasmtime }:
mkShellNoCC {
nativeBuildInputs = [ rust-bin.stable.latest.minimal ];
depsBuildBuild = [ wasmtime ];

View File

@ -1,7 +1,8 @@
{ lib, stdenv, symlinkJoin, pkgsTargetTarget, bash, gcc }:
{ lib, stdenv, symlinkJoin, pkgsTargetTarget, bash }:
{ pname, version, components }:
let
inherit (lib) optional optionalString;
inherit (stdenv) targetPlatform;
in
symlinkJoin {
name = pname + "-" + version;
@ -15,13 +16,16 @@ symlinkJoin {
# CC for build script linking.
# Workaround: should be `pkgsHostHost.cc` but `stdenv`'s cc itself have -1 offset.
depsHostHostPropagated = [ stdenv.cc ];
# CC for crate linking.
# Workaround: should be `pkgsHostTarget.cc` but `stdenv`'s cc itself have -1 offset.
propagatedBuildInputs = [ pkgsTargetTarget.stdenv.cc ];
# N.B. WASM targets don't need our CC.
propagatedBuildInputs =
optional (!targetPlatform.isWasm) pkgsTargetTarget.stdenv.cc;
# Link dependency for target, required by darwin std.
depsTargetTargetPropagated =
optional (stdenv.targetPlatform.isDarwin) [ pkgsTargetTarget.libiconv ];
optional (targetPlatform.isDarwin) [ pkgsTargetTarget.libiconv ];
postBuild = ''
# If rustc or rustdoc is in the derivation, we need to copy their
@ -46,9 +50,8 @@ symlinkJoin {
# symlinkJoin doesn't automatically handle it. Thus do it manually.
mkdir $out/nix-support
echo "$depsHostHostPropagated " >$out/nix-support/propagated-host-host-deps
echo "$propagatedBuildInputs " >$out/nix-support/propagated-build-inputs
'' + optionalString (stdenv.targetPlatform.isDarwin) ''
echo "$depsTargetTargetPropagated " >$out/nix-support/propagated-target-target-deps
[[ -z "$propagatedBuildInputs" ]] || echo "$propagatedBuildInputs " >$out/nix-support/propagated-build-inputs
[[ -z "$depsTargetTargetPropagated" ]] || echo "$depsTargetTargetPropagated " >$out/nix-support/propagated-target-target-deps
'';
meta.platforms = lib.platforms.all;

View File

@ -1,5 +1,5 @@
# Define component derivations and special treatments.
{ lib, stdenv, gnutar, autoPatchelfHook, zlib, gccForLibs
{ lib, stdenv, stdenvNoCC, gnutar, autoPatchelfHook, bintools, zlib, gccForLibs
, toRustTarget, removeNulls
}:
# Release version of the whole set.
@ -19,7 +19,7 @@ let
# These components link to `librustc_driver*.so` or `libLLVM*.so`.
linksToRustc = elem pname [ "clippy-preview" "rls-preview" "miri-preview" "rustc-dev" ];
in
stdenv.mkDerivation rec {
stdenvNoCC.mkDerivation rec {
inherit pname version src;
name = "${pname}-${version}-${platform}";
@ -31,15 +31,23 @@ let
nativeBuildInputs = [ gnutar ] ++
# Darwin doesn't use ELF, and they usually just work due to relative RPATH.
optional (!dontFixup && !hostPlatform.isDarwin) autoPatchelfHook;
optional (!dontFixup && !hostPlatform.isDarwin) autoPatchelfHook ++
# For `install_name_tool`.
optional (hostPlatform.isDarwin && linksToRustc) bintools;
buildInputs =
optional (elem pname [ "rustc" "cargo" "llvm-tools-preview" ]) zlib ++
# Nightly `rustc` since 2022-02-17 links to `libstdc++.so.6` on Linux.
# https://github.com/oxalica/rust-overlay/issues/73
optional (!dontFixup && !hostPlatform.isDarwin && pname == "rustc") gccForLibs.lib ++
optional linksToRustc self.rustc;
# Nightly `rustc` since 2022-02-17 links to `libstdc++.so.6` on Linux.
# https://github.com/oxalica/rust-overlay/issues/73
#
# N.B. `gcc` is a compiler which is sensitive to `targetPlatform`.
# We use `depsHostHost` instead of `buildInputs` to force it ignore the target,
# since binaries produced by `rustc` don't actually relies on this gccForLibs.
depsHostHost =
optional (!dontFixup && !hostPlatform.isDarwin && pname == "rustc") gccForLibs.lib;
dontConfigure = true;
dontBuild = true;