Skip to content

Support precompiled libraries #606

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

Closed
massimiliano-mantione opened this issue Aug 21, 2019 · 8 comments · Fixed by #629 or #719
Closed

Support precompiled libraries #606

massimiliano-mantione opened this issue Aug 21, 2019 · 8 comments · Fixed by #629 or #719
Assignees
Labels

Comments

@massimiliano-mantione
Copy link

I am trying to use a precompiled library but the build system does not recognize it properly.

The reason: I am mixing Rust code into an Arduino sketch.
I compile the Rust code into a static library and then link this library into the Arduino sketch.

To link it, I put the Rust library in the Arduino library folder with a proper library.properties file and directory structure.

This works perfectly for Teensy 3.5 and 4 boards.

I tried to do it for an STM32 board (specifically, a Nucleo L432KC), with the following library.properties file:

name=rust-main-lib
version=1.0.0
author=Massimiliano Mantione <[email protected]>
maintainer=Massimiliano Mantione <[email protected]>
sentence=A library to test Arduino-rust integration
paragraph=Just a test
category=Communication
url=http://github.com/massimiliano-mantione
architectures=*
includes=rust-main-lib.h
precompiled=true
ldflags=-lrust-main-lib

where find rust-main-lib from the Arduino libraries directory gives the following:

rust-main-lib
rust-main-lib/src
rust-main-lib/src/cortex-m4
rust-main-lib/src/cortex-m4/librust-main-lib.a
rust-main-lib/src/rust-main-lib.h
rust-main-lib/library.properties

but the build process terminates with the following error message:

Compiling libraries...
Compiling library "rust-main-lib"
Using library rust-main-lib at version 1.0.0 in folder: /home/massi/Arduino/libraries/rust-main-lib 
stat /home/massi/Arduino/libraries/rust-main-lib/src/cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard: no such file or directory
Error compiling for board Nucleo-32.

The message is confusing: the cortex-m4 directory is there, and it contains the precompiled library.

When doing the same for the Teensy boards if I did not create the CPU-specific directory the error message was the proper one (it could not find the library file).

How can this be fixed?

Or, if this is not the proper repository where to file the issue, where should I file it?

@fpistm
Copy link
Member

fpistm commented Aug 21, 2019

Hi @massimiliano-mantione
I never try to do this and do not see why you get this error.
It seems more an Arduino issue.
Anyway could you provide me your library and the sketch you try to build to test on my side.
Thanks

@fpistm fpistm added question ❓ Usually converted as a discussion waiting feedback Further information is required labels Aug 22, 2019
@fpistm
Copy link
Member

fpistm commented Aug 26, 2019

@massimiliano-mantione any update on this ? Thanks.

@fpistm
Copy link
Member

fpistm commented Aug 30, 2019

No feedback since and enough information to reproduce.
I close it.
@massimiliano-mantione feel free to comment and add requested information then I will reopen if needed.

@fpistm fpistm closed this as completed Aug 30, 2019
@massimiliano-mantione
Copy link
Author

massimiliano-mantione commented Aug 30, 2019

Sorry for the late reply.
I opened the issue just before leaving for vacation, which with hindsight is not nice :-/

There is this repository on github that shows what I am trying to do: rust-arduino-st-nucleo-l432kc.

It contains a small rust library, an arduino sketch, and a script that puts everything in place so that an arduino build of that sketch uses the rust library as an arduino precompiled library.

You should look at it at this commit, particularly at the "build.sh" script.

The script does the following:

  • it builds the rust library (don't worry about it for now)
  • it creates the directories for the library and the sketch
  • it copies the library, its header file and its library.properties file in place
  • it also copies the sketch in a proper place (this is actually useless)

After this, in principle, building the sketch should succeed.

I have been able to make this procedure work for a Teensy 3.5 board.

If I try this with stm32duino I get the error described at the beginning of this issue.

I am attaching a zip file of the full library directory, I hope this helps.

Thanks!

@massimiliano-mantione
Copy link
Author

rust-main-lib.zip
This is the zip file of the library dir.

@fpistm fpistm self-assigned this Aug 30, 2019
@fpistm fpistm reopened this Aug 30, 2019
@fpistm
Copy link
Member

fpistm commented Aug 30, 2019

Ok. Thanks for update.

@fpistm fpistm added arduino compatibility enhancement New feature or request and removed question ❓ Usually converted as a discussion labels Sep 3, 2019
@fpistm
Copy link
Member

fpistm commented Sep 3, 2019

Hi @massimiliano-mantione
I was able to build with your lib.
Referring to https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5:-Library-specification#libraryproperties-file-format

  • precompiled - (available from Arduino IDE 1.8.6/arduino-builder 1.4.0) (optional) set to true to allow the use of .a (archive) and .so (shared object) files. The .a/.so file must be located at src/{build.mcu} where {build.mcu} is the architecture name of the target the file was compiled for. Ex: cortex-m3 for the Arduino DUE. The static library should be linked as an ldflag.

In this core the build.mcu contains also fpu and float-abi options, that's why you get this error, instead of searching cortex-m4 it searches cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard.

So, to get it working, {build.mcu} should only contain cortex-mx value and no floating options.

fpistm added a commit to fpistm/Arduino_Core_STM32 that referenced this issue Sep 3, 2019
Library can provide a precompiled library.
See precompiled option here:
https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5:-Library-specification#libraryproperties-file-format

The .a(archive)/.so(shared object) file must be located at: `src/{build.mcu}`

So the `build.mcu` could not contain `fpu` and `float-abi` options
and should only contain `cortex-mx` value.

Else Arduino IDE, instead of searching `cortex-mx`, searches
`cortex-mx -mfpu=fpv4-sp-d16 -mfloat-abi=hard` if floating-point
options are set.

`build.flags.fp` has been added to contain floating-point options if any.

Fixes stm32duino#606

Signed-off-by: Frederic Pillon <[email protected]>
@fpistm
Copy link
Member

fpistm commented Sep 3, 2019

@massimiliano-mantione
I've submit a PR which fixes your issue.

Hello CONFIG
Config done
Hello PRE
Hello from Rust!
Hello from Rust!
Hello from Rust!
Hello from Rust!

fpistm added a commit that referenced this issue Sep 4, 2019
Library can provide a precompiled library.
See precompiled option here:
https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5:-Library-specification#libraryproperties-file-format

The .a(archive)/.so(shared object) file must be located at: `src/{build.mcu}`

So the `build.mcu` could not contain `fpu` and `float-abi` options
and should only contain `cortex-mx` value.

Else Arduino IDE, instead of searching `cortex-mx`, searches
`cortex-mx -mfpu=fpv4-sp-d16 -mfloat-abi=hard` if floating-point
options are set.

`build.flags.fp` has been added to contain floating-point options if any.

Fixes #606

Signed-off-by: Frederic Pillon <[email protected]>
@fpistm fpistm removed the waiting feedback Further information is required label Nov 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment