Building a single application using profiles with rebar3

For those of us who like to have all our Advent of Code creations in a single repo, that’s painful from a build perspective, because you really want to only build the current year most of the time. Unfortunately, rebar3 doesn’t support this using e.g. rebar3 compile aoc2024 (How to compile a single app in release? · Issue #1834 · erlang/rebar3 · GitHub).

Oh, but it does! Interested?

The answer lies in profiles.

In your rebar.config you can specify additional/different app directories based on profile. Thus you can do something like

rebar3 as aoc2024 do xref, dialyzer -i, eunit -c, cover -v

The relevant rebar.config content is

{profiles, [
    {aoc2023, [{project_app_dirs, ["apps/aoc2023", "libs/*"]}]},
    {aoc2024, [{project_app_dirs, ["apps/aoc2024", "libs/*"]}]}
]}.

Hope this helps someone :slight_smile:

8 Likes

This is a fantastic tip! Leveraging profiles in rebar3 to streamline the build process for a multi-year Advent of Code repository is a clever and efficient approach. It not only helps focus on the current year’s challenges but also keeps the build process organized and manageable.

The flexibility of profiles allows for tailored configurations, making it easier to handle differences across years without complicating the overall setup. It’s a great way to maintain a clean and efficient workflow while keeping everything in a single repository.

Thanks for sharing this insight - I’m sure it will be incredibly helpful for others tackling similar challenges! :christmas_tree::sparkles:

1 Like

NB if you want it to default to the current year, but build all years e.g in CI, the following config does that:

{project_app_dirs, ["apps/aoc2024", "libs/*"]}.

{profiles, [
    {ci, [{project_app_dirs, ["apps/*"]}]}
]}.
2 Likes