platformio / platform-atmelavr

Atmel AVR: development platform for PlatformIO
https://registry.platformio.org/platforms/platformio/atmelavr
Apache License 2.0
136 stars 104 forks source link

Can't find atmel-toolchain in alpine docker container #117

Open TimVosch opened 5 years ago

TimVosch commented 5 years ago

What kind of issue is this?

Possibly(?)


Configuration

Operating system: Arch Linux x64

PlatformIO Version (platformio --version): 3.6.1

Description of problem

I am running a docker container for my Continuous Integration, which I install platformio on. However when I try to build any project, PlatformIO reports that it can't find avr-gcc / avr-g++.

Steps to Reproduce

  1. Create docker image from: https://pastebin.com/pNWXjSgb
  2. Run docker container with name jenkins-blueocean
  3. Shell in (or create a pipeline but this is easier): sudo docker exec -i -t jenkins-blueocean /bin/bash
  4. Create a project: ex. pio init -b uno
  5. Insert something in main.cpp (see basic source below)
  6. pio run

Actual Results

https://pastebin.com/SqRkyrR5

Expected Results

Succesful build

If problems with PlatformIO Build System:

The content of platformio.ini:

; PlatformIO Project Configuration File
;
;   Build options: build flags, source filter
;   Upload options: custom upload port, speed and extra flags
;   Library options: dependencies, extra library storages
;   Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

[env:uno]
platform = atmelavr
board = uno
framework = arduino

Source file to reproduce issue:

int main() {

}

void loop() {

}

Additional info

I also tried different projects, non are working.

TimVosch commented 5 years ago

This is something else I noticed. Even though the toolchain files exist, it can't find/execute them?

Ignore the path in the terminal that isn't the docker container's path!

image

Better example:

image

TimVosch commented 5 years ago

This is interesting:

https://superuser.com/questions/1176200/no-such-file-when-it-exists

Edit Looks like alpine cant run the toolchain because it's build against glibc, which alpine doesn't have.

https://github.com/gliderlabs/docker-alpine/issues/219

TimVosch commented 5 years ago

Okay, Installing the toolchain with: https://github.com/takesako/alpine-iot or just apk add avr-libc almost works. It just can't find the correct spec?

https://pastebin.com/p4VEcY2v

TimVosch commented 5 years ago

Is there a way to tell PIO where to look for device-specs? I can't find any environment variables this quick.

Edit:

I pass the following build_flag with no success:

build_flags =
    -specs=/usr/lib/gcc/avr/6.1.0/device-specs/specs-atmega328p

Also tried:

build_flags =
        -specs=/var/jenkins_home/.platformio/packages/toolchain-atmelavr/lib/gcc/avr/5.4.0/device-specs/specs-atmega328p

Verbose works manually, not through PIO

So verbose outputs the following with the previous build_flag:

avr-g++ -o .pioenvs/uno/FrameworkArduino/HardwareSerial1.cpp.o -c -fno-exceptions -fno-threadsafe-statics -fpermissive -std=gnu++11 -specs=/var/jenkins_home/.platformio/packages/toolchain-atmelavr/lib/gcc/avr/5.4.0/device-specs/specs-atmega328p -Os -Wall -ffunction-sections -fdata-sections -flto -mmcu=atmega328p -DPLATFORMIO=30602 -DARDUINO_AVR_UNO -DF_CPU=16000000L -DARDUINO_ARCH_AVR -DARDUINO=10805 -I/root/.platformio/packages/framework-arduinoavr/cores/arduino -I/root/.platformio/packages/framework-arduinoavr/variants/standard /root/.platformio/packages/framework-arduinoavr/cores/arduino/HardwareSerial1.cpp

or

avr-g++ -o .pioenvs/uno/src/main.cpp.o -c -fno-exceptions -fno-threadsafe-statics -fpermissive -std=gnu++11 -specs=/var/jenkins_home/.platformio/packages/toolchain-atmelavr/lib/gcc/avr/5.4.0/device-specs/specs-atmega328p --version -Os -Wall -ffunction-sections -fdata-sections -flto -mmcu=atmega328p -DPLATFORMIO=30602 -DARDUINO_AVR_UNO -DF_CPU=16000000L -DARDUINO_ARCH_AVR -DARDUINO=10805 -Isrc -Iinclude -I/root/.platformio/packages/framework-arduinoavr/cores/arduino -I/root/.platformio/packages/framework-arduinoavr/variants/standard src/main.cpp

PIO still fails. If I 1-on-1 copy and paste this in the shell it works!? So there is probably some environment-variable that is set for PIO.

ivankravets commented 5 years ago

Yes, it seems that existing AVR toolchain for ARM is not compatible with Alpine distributive. It should work with Ubuntu/Debian. Temporary solution is to remove everything from ~/.platformio/packages/toolchain-atmelavr but keep package.json. PlatformIO will use the next binaries https://github.com/platformio/platform-atmelavr/blob/develop/builder/main.py#L93

Another solution is to fork https://github.com/platformio/platform-atmelavr and remove "toolchain" dependency.

Also, we have a feature request https://github.com/platformio/platformio-core/issues/1367 which will allow overriding platform dependencies from platformio.ini in PlatformIO Core 4.0

TimVosch commented 5 years ago

I got it working (atleast the building) with the build_flags below. I don't think each is necessary, but it works :man_shrugging: Note that /var/jenkins_home/ is usually your own home directory, however this is a jenkins docker container.

build_flags =
        -B/usr/lib/gcc/avr/6.1.0/
        -B/var/jenkins_home/.platformio/packages/toolchain-atmelavr/lib/gcc/avr/5.4.0/
        -I/var/jenkins_home/.platformio/packages/toolchain-atmelavr/lib/gcc/avr/5.4.0/include
        -I/var/jenkins_home/.platformio/packages/toolchain-atmelavr/avr/include/
        -I/var/jenkins_home/.platformio/packages/toolchain-atmelavr/libexec/gcc/avr/5.4.0/

~I will try and create a new image which will install the alpine atmel-toolchain and see if I can use some symlink magic to make it work.~

Update: I did not succeed in making a working image. I have quit on this approach currently. I am too busy with other stuff.