Skip to content
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

Use rebar3 for compilation and AVM packbeam generation. #971

Closed
wants to merge 2 commits into from

Conversation

fadushin
Copy link
Collaborator

@fadushin fadushin commented Dec 2, 2023

This PR changes the build of Erlang libraries and tests to use rebar3 as a build tool, instead of calling the Erlang compiler directly. The atomvm_rebar3_packbeam rebar3 plugin is used to create PackBEAM (.avm) files, instead of the C-based PackBEAM tool.

This PR includes the following changes:

  • The erlang libraries in the libs directory have been modifed to comply with rebar3 build conventions, including a src directory, an <application-name>.app.src file for each library, and a rebar.config.in file, for which CMake rules will generate a rebar.config with proper paths. Many of the changes in this directory also relate simply to file moves, in order to comply with rebar3 build conventions.
  • The alisp project has been folded into the eavmlib project, as we have no use case for building or deploying these modules separately.
  • The erlang tests, including unit tests and the estdlib and eavmlib, have been modified to also use rebar3. Many of the changes in this directory relate simply to file moves, in order to comply with rebar3 build conventions.
  • The Elixir builds have not been significantly modified, for example to use the mix tool and ExAtomVM plugin. That work can come later, once the ExAtomVM tool reaches functional parity with the atomvm_rebar3_plugin.
  • The Erlang and Elixir examples have not been changed to use the new build system, as we plan to deprecate these examples in favor of the atomvm_examples repository in the future.
  • The rp2040 test build has been modified to use the rebar3 build system, though some of the logic has been copied from the base build system. Due to a potentially missing feature in the atomvm_rebar3_plugin uf2create task, we have left use of the uf2tool.erl escript. A TODO has been left to identify the issue.
  • Many of the Github workflows have been modified to include and build rebar3 as well as various adjustments to resulting paths.
  • Several TODOs have been identified in the existing and new build system and have been identified with comments.

Benchmarks

The following benchmarks were run on MacOS, FreeBSD, and Linux systems (though the Linux system is running virtualized on FreeBSD, so numbers there should be taken with a grain of salt). Comparisons are made between build times on the master and this branch, for parallel and sequential builds using make and ninja, for all three platforms.

Results are represented in the following table:

Platform Build Type Command Elapsed Time (master) Elapsed Time (rebar-build)
MacOS clean make -j 8 2m51.213s 0m33.763s
MacOS rebuild make -j 8 0m5.306s 0m13.155s
MacOS clean ninja 2m41.689s 0m30.022s
MacOS rebuild ninja 0m4.336s 0m9.363s
MacOS clean make 5m48.742s 1m27.505s
MacOS rebuild make 0m14.352s 0m24.544s
FreeBSD clean make -j 8 1m5.755s 0m34.545s
FreeBSD rebuild make -j 8 0m2.386s 0m11.962s
FreeBSD clean ninja 0m57.580s 0m29.580s
FreeBSD rebuild ninja 0m1.661s 0m5.423s
FreeBSD clean make 3m32.387s 1m11.465s
FreeBSD rebuild make 0m7.584s 0m14.974s
Debian (virt) clean make -j 8 1m39.644s 0m34.479s
Debian (virt) rebuild make -j 8 0m10.828s 0m13.745s
Debian (virt) clean ninja 2m55.802s 0m38.964s
Debian (virt) rebuild ninja 0m5.002s 0m10.531s
Debian (virt) clean make 9m54.355s 1m51.219s
Debian (virt) rebuild make 0m26.210s 0m36.631s

Summary:

  • Clean builds are generally 2-3x faster using rebar than on master
  • Rebuilds (with no changes) are roughly 2x slower using rebar3
  • Ninja and parallel builds are roughly similar on clean builds, but Ninja outperforms on rebuilds.
  • Clean sequential builds on master are extremely slow. They are better with rebar3, as at least chunks of the Erlang code are built in parallel. This is especially true of the erlang unit tests.

Future Improvements

  • The Erlang unit tests are now packaged into an AVM. This may make them suitable for testing on ESP32, STM32, rp2040, etc.
  • Using the atomvm_rebar3_plugin tees up support for the OTP Application behavior, as the plugin will generate application.bin files from the created .app files, which are used at runtime by the OTP Application controller to determine which applications to load.
  • The Elixir builds should eventually use mix and the ExAtomVM plugin, but we have some work to do on the plugin to brin git up to parity. We have left the Elixir builds as is.

Notes

  • MacOS
    • OS: 11.7.10
    • Hardware: Late 2014 iMac 4 GHz Quad-Core Intel Core i7 32G RAM
  • FreeBSD
    • OS: FreeBSD freenas.local 13.1-RELEASE-p7 FreeBSD 13.1-RELEASE-p7 n245428-4dfb91682c1 TRUENAS amd64
    • Hardware: Intel(R) Xeon(R) CPU D-1518 @ 2.20GHz 8 core 32G RAM
  • Debian
    • OS: Linux debian 4.19.0-24-amd64 #1 SMP Debian 4.19.282-1 (2023-04-29) x86_64 GNU/Linux
    • Virtualization: FreeBSD BHyve 4 cores assigned, 4GB RAM assigned
    • Host OS: See FreeBSD
    • Hardware: See FreeBSD

These changes are made under both the "Apache 2.0" and the "GNU Lesser General
Public License 2.1 or later" license terms (dual license).

SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later

@UncleGrumpy
Copy link
Collaborator

I just did a test run with this PR and it looks like it is still building the C PackBEAM target. Should those build steps be removed?

@fadushin
Copy link
Collaborator Author

fadushin commented Dec 6, 2023

I just did a test run with this PR and it looks like it is still building the C PackBEAM target. Should those build steps be removed?

The Elixir build still requires PackBEAM.

@UncleGrumpy
Copy link
Collaborator

Right! I should have realized that.

@fadushin fadushin force-pushed the rebar-build branch 2 times, most recently from f1dd0f2 to 78c57cf Compare December 16, 2023 02:19
#
# SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
rebar.config
rebar.lock
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't we version lock files?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probabaly not in this case, because in most cases the dependencies are internal to this project, and we do not version them; nod do we put them in GitHub repositories structured in such a way that they can be pulled down.

# SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
rebar.config
rebar.lock
_checkouts/*
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sources directory is getting polluted in different places:

        libs/atomvmlib/_checkouts/
        libs/atomvmlib/rebar.config
        libs/atomvmlib/rebar.lock
        libs/eavmlib/rebar.config
        libs/eavmlib/rebar.lock
        libs/esp32boot/_checkouts/
        libs/esp32boot/rebar.config
        libs/esp32boot/rebar.lock
        libs/esp32devmode/_checkouts/
        libs/esp32devmode/rebar.config
        libs/esp32devmode/rebar.lock
        libs/estdlib/rebar.config
        libs/estdlib/rebar.lock
        libs/etest/rebar.config
        libs/etest/rebar.lock
        tests/code_load/rebar.config
        tests/code_load/rebar.lock
        tests/erlang_tests/include/code_load_pack_data.hrl
        tests/erlang_tests/include/export_test_module_data.hrl
        tests/erlang_tests/rebar.config
        tests/erlang_tests/rebar.lock
        tests/libs/eavmlib/_checkouts/
        tests/libs/eavmlib/rebar.config
        tests/libs/eavmlib/rebar.lock
        tests/libs/estdlib/_checkouts/
        tests/libs/estdlib/rebar.config
        tests/libs/estdlib/rebar.lock

We need to fix this before merging. Adding _checkouts/* to .gitignore is a workaround.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In progress...

@bettio
Copy link
Collaborator

bettio commented Jan 15, 2024

The alisp project has been folded into the eavmlib project, as we have no use case for building or deploying these modules separately.

Honestly my plan here is quite the opposite and I would further modularize libraries, such as I mention here #710.

@bettio
Copy link
Collaborator

bettio commented Jan 15, 2024

Tested release workflows, and I've got the following error:
Status:

build-libraries
Process completed with exit code 2.

Log:

[ 27%] Linking C executable test-structs
[ 27%] Built target test-structs
[ 27%] Creating code_load packbeam ...
/bin/sh: 1: rebar3: not found
make[2]: *** [tests/code_load/CMakeFiles/code_load_packbeam.dir/build.make:71: tests/code_load/CMakeFiles/code_load_packbeam] Error 127
make[1]: *** [CMakeFiles/Makefile2:1095: tests/code_load/CMakeFiles/code_load_packbeam.dir/all] Error 2
make: *** [Makefile:136: all] Error 2
Error: Process completed with exit code 2.

COMMAND mkdir -p _checkouts && cd _checkouts && ln -f -s ${CMAKE_SOURCE_DIR}/libs/${dep}
VERBATIM
)
endforeach()

add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/src
COMMAND ln -s -f ${CMAKE_CURRENT_SOURCE_DIR}/src
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't support it right now, but it would be nice (see #8) and this change would completely rule it out.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, not unless we use something like mklink. I suspect there are many other issues with Windows that would need to be addressed.

@fadushin fadushin marked this pull request as draft January 16, 2024 13:54
@fadushin
Copy link
Collaborator Author

Converted to DRAFT until I re-work the rebar3 projects in the build tree

@fadushin
Copy link
Collaborator Author

I am going to keep this branch open but close the issue, for a rethink of strategies.

@fadushin fadushin closed this Feb 15, 2024
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.

3 participants