Skip to content

Commit cfb71b2

Browse files
committed
Add Buildroot and mix.exs config to generated README
1 parent f0632c7 commit cfb71b2

2 files changed

Lines changed: 62 additions & 2 deletions

File tree

generate_toolchains.exs

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ defmodule ToolchainGenerator do
6161
app_name = "nerves_toolchain_#{target_tuple}"
6262
target_dir = Path.expand(app_name)
6363
config_dir = "configs/#{app_name}"
64+
versions = Map.get(version_metadata, app_name, [])
6465

6566
IO.puts("Generating #{target_dir}...")
6667

@@ -73,8 +74,9 @@ defmodule ToolchainGenerator do
7374
# Prepare bindings for EEx templates
7475
module_name = target_tuple_to_module_name(target_tuple)
7576
target_display = target_tuple |> to_string() |> String.replace("_", "-")
76-
included_components = build_included_components(Map.get(version_metadata, app_name, []))
77+
included_components = build_included_components(versions)
7778
package_licenses_list = format_string_list(build_package_licenses(included_components))
79+
external_toolchain_settings = build_external_toolchain_settings!(versions)
7880

7981
bindings = [
8082
module_name: module_name,
@@ -83,7 +85,9 @@ defmodule ToolchainGenerator do
8385
target_display: target_display,
8486
ctng_tag: Map.fetch!(toolchain_config, :ctng_tag),
8587
included_components: included_components,
86-
package_licenses_list: package_licenses_list
88+
package_licenses_list: package_licenses_list,
89+
linux_headers_series: external_toolchain_settings.linux_headers_series,
90+
libc_type: external_toolchain_settings.libc_type
8791
]
8892

8993
template_dir = Path.expand("template")
@@ -143,6 +147,34 @@ defmodule ToolchainGenerator do
143147
end)
144148
end
145149

150+
defp build_external_toolchain_settings!(versions) do
151+
versions_by_component = Map.new(versions)
152+
153+
%{
154+
linux_headers_series: linux_headers_series!(versions_by_component),
155+
libc_type: libc_type!(versions_by_component)
156+
}
157+
end
158+
159+
defp linux_headers_series!(versions_by_component) do
160+
versions_by_component
161+
|> Map.fetch!("Linux headers")
162+
|> String.split(".")
163+
|> Enum.take(2)
164+
|> case do
165+
[major, minor] -> "#{major}_#{minor}"
166+
_ -> raise "expected Linux headers version to include major and minor numbers"
167+
end
168+
end
169+
170+
defp libc_type!(versions_by_component) do
171+
cond do
172+
Map.has_key?(versions_by_component, "glibc") -> "GLIBC"
173+
Map.has_key?(versions_by_component, "musl") -> "MUSL"
174+
true -> raise "expected glibc or musl in toolchain version metadata"
175+
end
176+
end
177+
146178
defp build_package_licenses(included_components) do
147179
included_components
148180
|> Enum.map(&elem(&1, 2))

template/README.md.eex

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,34 @@ cross-compilers can be referenced in `mix`. See
1313
[nerves-toolchain](https://github.com/nerves-project/nerves-toolchain) for
1414
the scripts used to generate the actual cross-compiler.
1515

16+
## Using this toolchain in a Nerves system
17+
18+
Add this toolchain to your Nerves system project's `deps` in `mix.exs`:
19+
20+
```elixir
21+
{:<%= @app_name %>, "~> <toolchain version>", runtime: false}
22+
```
23+
24+
Then update `nerves_defconfig` to use the release artifact for this toolchain.
25+
The easiest way is to copy the external toolchain settings from this package's
26+
`defconfig`. In addition to pointing `BR2_TOOLCHAIN_EXTERNAL_URL` at the
27+
release archive for your host and setting the custom prefix, make sure the
28+
kernel headers, libc, and language/runtime options match:
29+
30+
```make
31+
BR2_TOOLCHAIN_EXTERNAL=y
32+
BR2_TOOLCHAIN_EXTERNAL_CUSTOM=y
33+
BR2_TOOLCHAIN_EXTERNAL_DOWNLOAD=y
34+
BR2_TOOLCHAIN_EXTERNAL_URL="https://github.com/nerves-project/toolchains/releases/download/<tag>/<artifact>"
35+
BR2_TOOLCHAIN_EXTERNAL_CUSTOM_PREFIX="<%= @target_display %>"
36+
BR2_TOOLCHAIN_EXTERNAL_HEADERS_<%= @linux_headers_series %>=y
37+
BR2_TOOLCHAIN_EXTERNAL_CUSTOM_<%= @libc_type %>=y
38+
# BR2_TOOLCHAIN_EXTERNAL_INET_RPC is not set
39+
BR2_TOOLCHAIN_EXTERNAL_CXX=y
40+
BR2_TOOLCHAIN_EXTERNAL_FORTRAN=y
41+
BR2_TOOLCHAIN_EXTERNAL_OPENMP=y
42+
```
43+
1644
<%= if @included_components != [] do %>
1745
## Included tool versions and licenses
1846

0 commit comments

Comments
 (0)