Skip to content

Commit

Permalink
arocc: init at 0-unstable-06-01
Browse files Browse the repository at this point in the history
  • Loading branch information
RossComputerGuy committed Jul 28, 2024
1 parent 8045879 commit 9f589ea
Show file tree
Hide file tree
Showing 9 changed files with 130 additions and 12 deletions.
7 changes: 5 additions & 2 deletions pkgs/build-support/cc-wrapper/add-flags.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@ for var in "${var_templates_bool[@]}"; do
mangleVarBool "$var" ${role_suffixes[@]+"${role_suffixes[@]}"}
done

# `-B@out@/bin' forces cc to use ld-wrapper.sh when calling ld.
NIX_CFLAGS_COMPILE_@suffixSalt@="-B@out@/bin/ $NIX_CFLAGS_COMPILE_@suffixSalt@"
# Arocc does not support "-B"
if [[ -z "@isArocc@" ]]; then
# `-B@out@/bin' forces cc to use ld-wrapper.sh when calling ld.
NIX_CFLAGS_COMPILE_@suffixSalt@="-B@out@/bin/ $NIX_CFLAGS_COMPILE_@suffixSalt@"
fi

# Export and assign separately in order that a failing $(..) will fail
# the script.
Expand Down
5 changes: 5 additions & 0 deletions pkgs/build-support/cc-wrapper/cc-wrapper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ if [ "$nonFlagArgs" = 0 ]; then
dontLink=1
fi

# Arocc does not link
if [ "@isArocc@" = 1 ]; then
dontLink=1
fi

# Optionally filter out paths not refering to the store.
if [[ "${NIX_ENFORCE_PURITY:-}" = 1 && -n "$NIX_STORE" ]]; then
kept=()
Expand Down
29 changes: 19 additions & 10 deletions pkgs/build-support/cc-wrapper/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
, propagateDoc ? cc != null && cc ? man
, extraTools ? [], extraPackages ? [], extraBuildCommands ? ""
, nixSupport ? {}
, isGNU ? false, isClang ? cc.isClang or false, isZig ? cc.isZig or false, isCcache ? cc.isCcache or false
, isGNU ? false, isClang ? cc.isClang or false, isZig ? cc.isZig or false
, isArocc ? cc.isArocc or false, isCcache ? cc.isCcache or false
, gnugrep ? null
, expand-response-params
, libcxx ? null
Expand Down Expand Up @@ -305,6 +306,9 @@ stdenvNoCC.mkDerivation {

outputs = [ "out" ] ++ optionals propagateDoc [ "man" "info" ];

# Cannot be in "passthru" due to "substituteAll"
inherit isArocc;

passthru = {
inherit targetPrefix suffixSalt;
# "cc" is the generic name for a C compiler, but there is no one for package
Expand Down Expand Up @@ -392,6 +396,10 @@ stdenvNoCC.mkDerivation {
ln -s ${targetPrefix}clang $out/bin/${targetPrefix}cc
export named_cc=${targetPrefix}clang
export named_cxx=${targetPrefix}clang++
elif [ -e $ccPath/arocc ]; then
wrap ${targetPrefix}arocc $wrapper $ccPath/arocc
ln -s ${targetPrefix}arocc $out/bin/${targetPrefix}cc
export named_cc=${targetPrefix}arocc
fi
if [ -e $ccPath/${targetPrefix}g++ ]; then
Expand Down Expand Up @@ -476,7 +484,7 @@ stdenvNoCC.mkDerivation {
#
# TODO(@Ericson2314): Remove this after stable release and force
# everyone to refer to bintools-wrapper directly.
+ ''
+ optionalString (!isArocc) ''
if [[ -f "$bintools/nix-support/dynamic-linker" ]]; then
ln -s "$bintools/nix-support/dynamic-linker" "$out/nix-support"
fi
Expand All @@ -492,7 +500,7 @@ stdenvNoCC.mkDerivation {
echo "-B${gccForLibs}/lib/gcc/${targetPlatform.config}/${gccForLibs.version}" >> $out/nix-support/cc-cflags
''
+ optionalString useGccForLibs ''
+ optionalString (useGccForLibs && !isArocc) ''
echo "-L${gccForLibs}/lib/gcc/${targetPlatform.config}/${gccForLibs.version}" >> $out/nix-support/cc-ldflags
echo "-L${gccForLibs_solib}/lib" >> $out/nix-support/cc-ldflags
''
Expand All @@ -518,9 +526,9 @@ stdenvNoCC.mkDerivation {
''
# this ensures that when clang passes -lgcc_s to lld (as it does
# when building e.g. firefox), lld is able to find libgcc_s.so
+ concatMapStrings (libgcc: ''
+ optionals (!isArocc) (concatMapStrings (libgcc: ''
echo "-L${libgcc}/lib" >> $out/nix-support/cc-ldflags
'') (toList (gccForLibs.libgcc or [])))
'') (toList (gccForLibs.libgcc or []))))

##
## General libc support
Expand All @@ -540,9 +548,10 @@ stdenvNoCC.mkDerivation {
+ optionalString (libc != null) (''
touch "$out/nix-support/libc-cflags"
touch "$out/nix-support/libc-ldflags"
'' + optionalString (!isArocc) ''
echo "-B${libc_lib}${libc.libdir or "/lib/"}" >> $out/nix-support/libc-crt1-cflags
'' + optionalString (!(cc.langD or false)) ''
echo "-idirafter ${libc_dev}${libc.incdir or "/include"}" >> $out/nix-support/libc-cflags
echo "-${if isArocc then "I" else "idirafter"} ${libc_dev}${libc.incdir or "/include"}" >> $out/nix-support/libc-cflags
'' + optionalString (isGNU && (!(cc.langD or false))) ''
for dir in "${cc}"/lib/gcc/*/*/include-fixed; do
echo '-idirafter' ''${dir} >> $out/nix-support/libc-cflags
Expand Down Expand Up @@ -598,15 +607,15 @@ stdenvNoCC.mkDerivation {
# ${cc_solib}/lib64 (even though it does actually search there...)..
# This confuses libtool. So add it to the compiler tool search
# path explicitly.
+ optionalString (!nativeTools) ''
+ optionalString (!nativeTools && !isArocc) ''
if [ -e "${cc_solib}/lib64" -a ! -L "${cc_solib}/lib64" ]; then
ccLDFlags+=" -L${cc_solib}/lib64"
ccCFlags+=" -B${cc_solib}/lib64"
fi
ccLDFlags+=" -L${cc_solib}/lib"
ccCFlags+=" -B${cc_solib}/lib"
'' + optionalString cc.langAda or false ''
'' + optionalString (cc.langAda or false && !isArocc) ''
touch "$out/nix-support/gnat-cflags"
touch "$out/nix-support/gnat-ldflags"
basePath=$(echo $cc/lib/*/*/*)
Expand All @@ -627,7 +636,7 @@ stdenvNoCC.mkDerivation {
+ optionalString propagateDoc ''
ln -s ${cc.man} $man
ln -s ${cc.info} $info
'' + optionalString (cc.langD or cc.langJava or false) ''
'' + optionalString (cc.langD or cc.langJava or false && !isArocc) ''
echo "-B${zlib}${zlib.libdir or "/lib/"}" >> $out/nix-support/libc-cflags
''

Expand Down Expand Up @@ -668,7 +677,7 @@ stdenvNoCC.mkDerivation {
hardening_unsupported_flags+=" stackprotector"
''

+ optionalString (libc != null && targetPlatform.isAvr) ''
+ optionalString (libc != null && targetPlatform.isAvr && !isArocc) ''
for isa in avr5 avr3 avr4 avr6 avr25 avr31 avr35 avr51 avrxmega2 avrxmega4 avrxmega5 avrxmega6 avrxmega7 tiny-stack; do
echo "-B${getLib libc}/avr/lib/$isa" >> $out/nix-support/libc-crt1-cflags
done
Expand Down
44 changes: 44 additions & 0 deletions pkgs/development/compilers/arocc/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
lib,
fetchFromGitHub,
callPackage,
zig_0_13,
}:
let
versions = [
{
zig = zig_0_13;
version = "0-unstable-06-01";
src = fetchFromGitHub {
owner = "Vexu";
repo = "arocc";
rev = "55cb6d1b682b83f75ad4f60e34c6fcd2336e8531";
hash = "sha256-xs3zNQIC5drrQYT4nxL7Q69xSEdbdMv5+3hQpsX3q5A=";
};
}
];

mkPackage =
{
zig,
version,
src,
}:
callPackage ./package.nix { inherit zig version src; };

pkgsList = lib.map mkPackage versions;

pkgsAttrsUnwrapped = lib.listToAttrs (
lib.map (pkg: lib.nameValuePair "${pkg.version}-unwrapped" pkg) pkgsList
);
pkgsAttrsWrapped = lib.listToAttrs (
lib.map (pkg: lib.nameValuePair pkg.version pkg.wrapped) pkgsList
);

pkgsAttrs = pkgsAttrsWrapped // pkgsAttrsUnwrapped;
in
{
latest-unwrapped = lib.last pkgsList;
latest = (lib.last pkgsList).wrapped;
}
// pkgsAttrs
33 changes: 33 additions & 0 deletions pkgs/development/compilers/arocc/package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
lib,
stdenv,
wrapCCWith,
overrideCC,
zig,
version,
src,
}:
stdenv.mkDerivation (finalAttrs: {
pname = "arocc";
inherit version src;

nativeBuildInputs = [ zig.hook ];

passthru = {
inherit zig;
isArocc = true;
wrapped = wrapCCWith { cc = finalAttrs.finalPackage; };
stdenv = overrideCC stdenv finalAttrs.passthru.wrapped;
};

meta = {
description = "C compiler written in Zig.";
homepage = "http://aro.vexu.eu/";
license = with lib.licenses; [
mit
unicode-30
];
maintainers = with lib.maintainers; [ RossComputerGuy ];
mainProgram = "arocc";
};
})
2 changes: 2 additions & 0 deletions pkgs/stdenv/cross/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ in lib.init bootStages ++ [
then buildPackages.llvmPackages.clang
else if crossSystem.useZig or false
then buildPackages.zig.cc
else if crossSystem.useArocc or false
then buildPackages.arocc
else buildPackages.gcc;

extraNativeBuildInputs = old.extraNativeBuildInputs
Expand Down
6 changes: 6 additions & 0 deletions pkgs/top-level/all-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16662,6 +16662,7 @@ with pkgs;

isGNU = cc.isGNU or false;
isClang = cc.isClang or false;
isArocc = cc.isArocc or false;
isZig = cc.isZig or false;

inherit cc bintools libc libcxx extraPackages nixSupport zlib;
Expand Down Expand Up @@ -24698,6 +24699,11 @@ with pkgs;

zigStdenv = if stdenv.cc.isZig then stdenv else lowPrio zig.passthru.stdenv;

aroccPackages = recurseIntoAttrs (callPackage ../development/compilers/arocc {});
arocc = aroccPackages.latest;

aroccStdenv = if stdenv.cc.isArocc then stdenv else lowPrio arocc.cc.passthru.stdenv;

zimlib = callPackage ../development/libraries/zimlib { };

zita-convolver = callPackage ../development/libraries/audio/zita-convolver { };
Expand Down
1 change: 1 addition & 0 deletions pkgs/top-level/release.nix
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ let
agdaPackages = packagePlatforms pkgs.agdaPackages;

pkgsLLVM.stdenv = [ "x86_64-linux" "aarch64-linux" ];
pkgsArocc.stdenv = [ "x86_64-linux" "aarch64-linux" ];
pkgsZig.stdenv = [ "x86_64-linux" "aarch64-linux" ];
pkgsMusl.stdenv = [ "x86_64-linux" "aarch64-linux" ];
pkgsStatic.stdenv = [ "x86_64-linux" "aarch64-linux" ];
Expand Down
15 changes: 15 additions & 0 deletions pkgs/top-level/stage.nix
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,21 @@ let
};
};

pkgsArocc = nixpkgsFun {
overlays = [
(self': super': {
pkgsArocc = super';
})
] ++ overlays;
# Bootstrap a cross stdenv using the Aro C compiler.
# This is currently not possible when compiling natively,
# so we don't need to check hostPlatform != buildPlatform.
crossSystem = stdenv.hostPlatform // {
useArocc = true;
linker = "lld";
};
};

pkgsZig = nixpkgsFun {
overlays = [
(self': super': {
Expand Down

0 comments on commit 9f589ea

Please sign in to comment.