Skip to content

Allow precompiled libs #219

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 14, 2017
Merged

Conversation

facchinm
Copy link
Member

Allow dynamic and static libraries linking at runtime.
Please note that no library of this kind will be included in the library manager since we would be unable to enforce that the license is compliant with the actual library "content"

A precompiled library should provide:
- a header file defining the functions (like a normal library)
- some folders named after {build.mcu} containing the precompiled files

It should declare
- precompiled=true in its library.properties

The precompiled files can be either static (.a) or dynamic (.so).
In the latter case, the maintainer should take extra care to ensure that the exported symbol versions are matching the remote board's
As of now, Library.Name maps to the folder it resides in, not the name declared in library.properties
It could be a bug or a feature, anyway since need to we use the real library name, extract it and save in the structure
Combined with Library.precompiled flag, allows a developer to ship a precompiled library.

The linker (ld in our case) needs static libraries to be explicitely included in the build (it doesn't try any heuristic).
Luckily, "including" a dynamic library in this way works as well, so we can avoid the "-L" and "-l" dance
@ArduinoBot
Copy link
Contributor

✅ Build completed.

⬇️ Build URL: http://downloads.arduino.cc/PR/arduino-builder/arduino-builder-219.zip

ℹ️ To test this build:

  1. Replace arduino-builder binary (you can find it where you installed the IDE) with the provided one

Since ld uses absolute paths in certain conditions, adopt a different strategy for dynamic libraries. "compiler.c.elf.extra_flags" must be defined and used in "recipe.c.combine" (at least)
@ArduinoBot
Copy link
Contributor

✅ Build completed.

⬇️ Build URL: http://downloads.arduino.cc/PR/arduino-builder/arduino-builder-219.zip

ℹ️ To test this build:

  1. Replace arduino-builder binary (you can find it where you installed the IDE) with the provided one

@kgoveas
Copy link

kgoveas commented Nov 17, 2017

@facchinm ,

Do you know when this will be part of the Arduino-builder release?

@cmaglie cmaglie deleted the allow_precompiled_libs branch January 11, 2018 10:10
@cmaglie cmaglie added this to the 1.4.0 milestone Sep 10, 2018
@Corjan85
Copy link

Hi,

Is there any news on when this will be included into the official Arduino release?
The wiki says it should have been available in 1.8.6, but it didn't make it it seems :)

Corjan

@facchinm
Copy link
Member Author

@Corjan85 it is included in IDE 1.8.6 and upwards; for an example of the usage, take a look at arduino/ArduinoCore-samd@37c8d4f (the commit is used to link https://github.com/vidor-libraries/USBBlaster library)

@facchinm
Copy link
Member Author

The rule name has been changed here to avoid clash with already defined flags

@Corjan85
Copy link

Hi,

Thanks for your reply.

I think have done the same as the USBBlaster library. This is my library.properties:

name=SI Message Port
version=1.0.0
author=Sim Innovations
maintainer=Sim Innovations <[email protected]>
sentence=Allows to couple Arduino projects to Air Manager or Air Player
paragraph=
category=Device Control
url=https://www.siminnovations.com
architectures=*
precompiled=true
ldflags=-lMessagePort -lMessagePortDriver -lSiBase

This is what happens during the linking step:

C:\\Program Files (x86)\\Arduino\\hardware\\tools\\avr/bin/avr-gcc" -w -Os -g -flto -fuse-linker-plugin -Wl,--gc-sections -mmcu=atmega328p -o "C:\\Users\\corja\\AppData\\Local\\Temp\\arduino_build_186642/BasicExample.ino.elf" "C:\\Users\\corja\\AppData\\Local\\Temp\\arduino_build_186642\\sketch\\BasicExample.ino.cpp.o" "C:\\Users\\corja\\AppData\\Local\\Temp\\arduino_build_186642\\libraries\\SiMessagePort\\si_message_port.cpp.o" "C:\\Users\\corja\\AppData\\Local\\Temp\\arduino_build_186642/core\\core.a" "-LC:\\Users\\corja\\AppData\\Local\\Temp\\arduino_build_186642" -lm

It seems the ldflags are ignored. The custom build arduino_builder.exe higher up in this post seems to add the ldflags.

Could it maybe be a feature that is only supported on SAM devices? Since the USBBlaster only targets SAM. I'm targetting atmega328p, atmega2560 and ATmega32U4.

Any help is appreciated,

Corjan

@Corjan85
Copy link

Forget to tell, but I'm using Arduino 1.8.7.

I have done a reinstall, and made sure to delete everything from program files and user documents folder, just in case...

Corjan

@facchinm
Copy link
Member Author

Yes, at the moment only samd core is supported (in beta). Adding the flag to avr core is trivial but we haven't done it yet; anyway, if you want to experiment on your library and then propose a PR to https://github.com/arduino/ArduinoCore-avr I'll be glad to take a look and merge it!

@Corjan85
Copy link

Ah, that makes sense :)
Will make a fork and see how far I get.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants