Skip to content

Replace nerves_toolchain_ctng dependency with template-based code embedding#148

Draft
Copilot wants to merge 17 commits intomainfrom
copilot/prototype-toolchain-package
Draft

Replace nerves_toolchain_ctng dependency with template-based code embedding#148
Copilot wants to merge 17 commits intomainfrom
copilot/prototype-toolchain-package

Conversation

Copy link

Copilot AI commented Feb 10, 2026

Toolchain packages had ~90% duplicate code across mix.exs files. External nerves_toolchain_ctng dependency caused version conflicts.

Changes

  • Template system (template/)

    • EEx templates for mix.exs and README.md
    • Embedded copy of nerves_toolchain_ctng code (lib, scripts, patches, build.sh, defaults)
  • Elixir-based generation

    • generate_toolchains.exs - Elixir script with embedded configuration for all 12 toolchains
    • Uses EEx for proper template processing
    • Module names automatically derived from target_tuple (no manual specification needed)
    • Makefile - make generate regenerates all packages
  • Configuration structure (configs/)

    • Per-toolchain essential files stored in configs/<toolchain>/ directories
    • Contains defconfig, VERSION, LICENSE, and mingw32_x86_64_defconfig (where applicable)
    • Toolchain package directories are fully generated and excluded from repository
  • Updated toolchain packages

    • Removed {:nerves_toolchain_ctng, path: "../nerves_toolchain_ctng"} dependency
    • All toolchain directories removed from repository (generated on-demand)
    • Added toolchain directories to root .gitignore
    • No .gitignore or mix.lock files in generated packages
    • Standardized description format (hyphens vs underscores)

Template structure

defmodule <%= @module_name %>.MixProject do
  defp deps do
    [{:nerves, "<%= @nerves_version %>", runtime: false}]
  end
  
  defp package_files do
    ["lib", "patches", "scripts", "build.sh", "defaults",
     <%= @package_files_list %>]
  end
end

Repository structure

  • template/ - EEx templates and embedded nerves_toolchain_ctng code
  • configs/ - Per-toolchain essential files (defconfig, VERSION, LICENSE)
  • generate_toolchains.exs - Generator with configuration
  • Toolchain directories created by running make generate

Each toolchain now self-contained. All generated code is created locally via make generate and excluded from the repository. Update shared code by modifying template/ and running make generate.

Original prompt

The toolchains packages all have a ton of duplication. Also it has turned out that keeping shared code in nerves_toolchain_ctng causes dependency versioning conflicts. Prototype a template toolchain package that takes a toolchain configuration and expands into a toolchain library with the nerves_toolchain_ctng code inside of it. Create a top level Makefile that instantiates all existing toolchains.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Prototype template toolchain package with shared code Replace nerves_toolchain_ctng dependency with template-based code embedding Feb 10, 2026
Copilot AI requested a review from fhunleth February 10, 2026 12:54
Copy link
Member

@fhunleth fhunleth left a comment

Choose a reason for hiding this comment

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

@copilot This is good. Please use Elixir instead of Python especially so that EEx can be used to process the .eex files. Also remove the generated code from the repository.

Copy link
Author

Copilot AI commented Feb 10, 2026

@copilot This is good. Please use Elixir instead of Python especially so that EEx can be used to process the .eex files. Also remove the generated code from the repository.

Done! Replaced Python with Elixir (generate_toolchains.exs) using EEx for template processing, and removed all generated code from the repository. Users now run make generate to create the embedded files locally. See commit 27ceef8.

@toolchains [
%{
target_tuple: :aarch64_nerves_linux_gnu,
module_name: "NervesToolchainAarch64NervesLinuxGnu",
Copy link
Member

Choose a reason for hiding this comment

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

@copilot Remove :module_name and create it from the target_tuple. I don't see the defconfig settings for each target. I think that was deleted.

Also remove all of the toolchain directories. There's no need for storing the .gitignore files. Don't generate mix.lock files either.

Copy link
Author

Choose a reason for hiding this comment

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

Done! Changes in commit d0f7193:

  • Removed :module_name from config - now auto-generated from target_tuple via target_tuple_to_module_name/1
  • Moved defconfig files (and VERSION, LICENSE) to configs/ directory - they weren't deleted
  • Removed all toolchain directories from repository
  • Added toolchain directories to root .gitignore
  • Generator no longer creates mix.lock files
  • No .gitignore files in generated packages

Copilot AI requested a review from fhunleth February 10, 2026 13:58
@fhunleth fhunleth force-pushed the gcc-15 branch 2 times, most recently from fdc2ffe to e5be2d5 Compare February 11, 2026 01:34
Base automatically changed from gcc-15 to main February 11, 2026 14:11
Copilot AI and others added 12 commits February 11, 2026 15:59
- Create template/ directory with EEx templates
- Create generate_toolchains.py to instantiate toolchains
- Create toolchains.exs configuration file
- Create top-level Makefile for building toolchains
- Embed nerves_toolchain_ctng code in each package
- Remove dependency on nerves_toolchain_ctng path

Co-authored-by: fhunleth <64669+fhunleth@users.noreply.github.com>
Co-authored-by: fhunleth <64669+fhunleth@users.noreply.github.com>
Co-authored-by: fhunleth <64669+fhunleth@users.noreply.github.com>
Added lib/, scripts/, build.sh, patches/, and defaults/
to the package_files list so they are included when
publishing to hex.pm

Co-authored-by: fhunleth <64669+fhunleth@users.noreply.github.com>
- Rewrote generate_toolchains.py as generate_toolchains.exs using Elixir
- Uses EEx for proper template processing
- Removed all generated code from toolchain directories
- Added .gitignore entries for generated files
- Updated documentation to reflect Elixir-based approach
- Generated code is now excluded from repository

Co-authored-by: fhunleth <64669+fhunleth@users.noreply.github.com>
…hain dirs

- Remove module_name from config, derive it from target_tuple
- Move defconfig, VERSION, LICENSE to configs/ directory
- Remove all toolchain directories from repository
- Add toolchain directories to .gitignore
- Generator now copies from configs/ and creates full toolchain packages
- Updated documentation to reflect new structure

Co-authored-by: fhunleth <64669+fhunleth@users.noreply.github.com>
@fhunleth fhunleth force-pushed the copilot/prototype-toolchain-package branch from d0f7193 to 6f05c2f Compare February 12, 2026 18:18
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.

2 participants