Open gesturbjarkason opened 5 years ago
I don't know if this does enough, but you could try adding something like,
avrgcc-wrapper = pkgs.stdenv.mkDerivation rec {
name = "avrgcc-wrapper-${version}";
version = pkgs.stdenv.lib.strings.getVersion pkgs.avrgcc.name;
nativeBuildInputs = [ pkgs.makeWrapper ];
builder = pkgs.writeText "builder.sh" ''
source $stdenv/setup
mkdir -p $out/bin $out/lib
for exe in gcc g++; do
makeWrapper "${pkgs.avrgcc}/bin/avr-$exe" "$out/bin/avr-$exe" --add-flags "-B${pkgs.avrlibc}/avr/lib -isystem ${pkgs.avrlibc}/avr/include"
done
ln -s ${pkgs.avrgcc}/lib/* $out/lib/
'';
};
to your config.nix
. If I do that, I can compile your test program but I haven't tried running it.
If this does work, we should add it to nixpkgs
as I agree with your assessment that the status quo seems incomplete.
Thanks a lot, by adding -B${pkgs.avrlibc}/avr/lib
the build now succeeds!
You wrapper derivation can probably be simplified to:
avrgcc-wrapper = pkgs.stdenv.mkDerivation rec {
name = "avrgcc-wrapper-${version}";
version = pkgs.stdenv.lib.strings.getVersion pkgs.avrgcc.name;
nativeBuildInputs = [ pkgs.makeWrapper ];
buildCommand = ''
mkdir -p $out/bin
for exe in gcc g++; do
makeWrapper "${pkgs.avrgcc}/bin/avr-$exe" "$out/bin/avr-$exe" --add-flags "-B${pkgs.avrlibc}/avr/lib -isystem ${pkgs.avrlibc}/avr/include"
done
ln -s ${pkgs.avrgcc}/lib $out
'';
};
But I don't feel competent to add it to nixpkgs, so I'm leaving this issue open for now.
Awesome! Do you know if we need to wrap more of the avr-
executables, or is it enough to have gcc
and g++
(along with a tool for flashing the chip)?
It's enough for all AVR-related workflows I can think of.
The little bits of ceremony of having a file for builder
(rather than a string) and sourcing $stdenv/setup
to get coreutils
on $PATH
are needed (I think) when building as part of nixpkgs
.
Great, thanks for the patch!
buildCommand
is a shorthand for running a custom command in a stdenv
environment, it perfectly fits your use case.
Another nit: Why are you linking the contents of $avrgcc/lib
and not the lib dir itself?
Thank you for your contributions.
This has been automatically marked as stale because it has had no activity for 180 days.
If this is still important to you, we ask that you leave a comment below. Your comment can be as simple as "still important to me". This lets people see that at least one person still cares about this. Someone will have to do this at most twice a year if there is no other activity.
Here are suggestions that might help resolve this more quickly:
I think this issue can be closed. Executing nix-shell -p pkgsCross.avr.buildPackages.gcc --run 'avr-gcc -mmcu=atmega8 main.c'
with the above main.c
file on Linux creates an a.out file. This was probably fixed in #48286.
Reopen if this is still an issue.
is still an issue; while compiling for mega devices works fine it's currently not possible to compile for tiny devices without adding a -B
argument as described earlier.
Can confirm that attinys are broken, atmegas are not.
still an issue (fails when trying -mmcu=attiny2313a
), the -B fix still works
Still happening:
$ nix-shell --pure -p pkgsCross.avr.buildPackages.gcc --run 'avr-gcc'
avr-gcc: error: unrecognized command-line option '-iframework'
my setup:
- system: `"aarch64-darwin"`
- host os: `Darwin 23.5.0, macOS 14.5`
- multi-user?: `yes`
- sandbox: `no`
- version: `nix-env (Nix) 2.18.4`
- channels(root): `"nixpkgs"`
- nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixpkgs`
version:
nix-shell --pure -p pkgsCross.avr.buildPackages.gcc --run 'avr-gcc -v'
Using built-in specs.
Reading specs from /nix/store/6kipcsjy6ypm8xl1h2sp0b2s8pwssfcc-avr-gcc-13.2.0/lib/gcc/avr/13.2.0/device-specs/specs-avr2
COLLECT_GCC=/nix/store/6kipcsjy6ypm8xl1h2sp0b2s8pwssfcc-avr-gcc-13.2.0/bin/avr-gcc
COLLECT_LTO_WRAPPER=/nix/store/6kipcsjy6ypm8xl1h2sp0b2s8pwssfcc-avr-gcc-13.2.0/libexec/gcc/avr/13.2.0/lto-wrapper
Target: avr
Configured with: ../gcc-13.2.0/configure --prefix=/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-avr-gcc-13.2.0 --with-gmp-include=/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-gmp-with-cxx-6.3.0-dev/include --with-gmp-lib=/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-gmp-with-cxx-6.3.0/lib --with-mpfr-include=/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-mpfr-4.2.1-dev/include --with-mpfr-lib=/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-mpfr-4.2.1/lib --with-mpc=/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-libmpc-1.3.1 --with-native-system-header-dir=/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-avr-libc-avr-2.1.0/avr/include --with-build-sysroot=/ --with-gxx-include-dir=/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-avr-gcc-13.2.0/include/c++/13.2.0/ --program-prefix=avr- --enable-lto --disable-libstdcxx-pch --without-included-gettext --with-system-zlib --enable-static --enable-languages=c,c++ --enable-multilib --disable-libquadmath --disable-shared --enable-plugin --disable-libcc1 --with-as=/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-avr-binutils-wrapper-2.41/bin/avr-as --with-ld=/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-avr-binutils-wrapper-2.41/bin/avr-ld --with-headers=/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-avr-libc-avr-2.1.0/avr/include --enable-__cxa_atexit --enable-long-long --enable-threads=single --enable-nls --with-avrlibc --build=aarch64-apple-darwin --host=aarch64-apple-darwin --target=avr
Thread model: single
Supported LTO compression algorithms: zlib
I'm unable to build the following trivial AVR example:
On other Linux distros, after installing the AVR dependencies (e.g.
apt-get install build-essential gcc-avr binutils-avr avr-libc
), the source can simply be built withavr-gcc -mmcu=atmega8 main.c
.On NixOS, the following fails because of missing include and library paths:
After manually setting the extra paths,
I'm still getting an error:
Note that
crtatmega8.o
exists in the libpath:ls ${libc}/avr/lib/avr4/crtatmega8.o
How can I build this example? Would it be possible to make the NixOS build process as painless as in other distros?
Environment
I'm using version
18.09.git.8cfce96
(the current 18.09 channel version)