Skip to content

Commit

Permalink
Merge pull request #81 from vkottler/dev/2.8.0
Browse files Browse the repository at this point in the history
2.8.0 - Add UF2 generation support to native
  • Loading branch information
vkottler authored Oct 27, 2023
2 parents 48016dd + 8c26d8d commit d4cfd5e
Show file tree
Hide file tree
Showing 11 changed files with 109 additions and 19 deletions.
11 changes: 10 additions & 1 deletion .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ jobs:
- run: pip${{matrix.python-version}} install -e .
- run: mk python-editable
if: matrix.system == 'ubuntu-latest'
- name: setup clang 17
run: |
wget https://apt.llvm.org/llvm.sh
chmod +x ./llvm.sh
sudo ./llvm.sh 17
rm llvm.sh
if: matrix.system == 'ubuntu-latest'
- run: sudo apt-get install gcc-13 g++-13 clang-17 clang-format-17
if: matrix.system == 'ubuntu-latest'
# End project-specific setup.

- run: mk python-sa-types
Expand Down Expand Up @@ -76,7 +85,7 @@ jobs:
- run: |
mk python-release owner=vkottler \
repo=yambs version=2.7.5
repo=yambs version=2.8.0
if: |
matrix.python-version == '3.11'
&& matrix.system == 'ubuntu-latest'
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
=====================================
generator=datazen
version=3.1.4
hash=b26d761fc77bb1ddee83a2faa6a6fa5f
hash=95602563e86f0658fcab5efca45060d1
=====================================
-->

# yambs ([2.7.5](https://pypi.org/project/yambs/))
# yambs ([2.8.0](https://pypi.org/project/yambs/))

[![python](https://img.shields.io/pypi/pyversions/yambs.svg)](https://pypi.org/project/yambs/)
![Build Status](https://github.com/vkottler/yambs/workflows/Python%20Package/badge.svg)
Expand Down
11 changes: 11 additions & 0 deletions local/configs/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ ci_local:
- "- run: mk python-editable"
- " if: matrix.system == 'ubuntu-latest'"

- "- name: setup clang 17"
- " run: |"
- " wget https://apt.llvm.org/llvm.sh"
- " chmod +x ./llvm.sh"
- " sudo ./llvm.sh 17"
- " rm llvm.sh"
- " if: matrix.system == 'ubuntu-latest'"

- "- run: sudo apt-get install gcc-13 g++-13 clang-17 clang-format-17"
- " if: matrix.system == 'ubuntu-latest'"

requirements:
- datazen
- vcorelib>=2.4.2
Expand Down
4 changes: 2 additions & 2 deletions local/variables/package.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
major: 2
minor: 7
patch: 5
minor: 8
patch: 0
entry: mbs
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta:__legacy__"

[project]
name = "yambs"
version = "2.7.5"
version = "2.8.0"
description = "Yet another meta build-system."
readme = "README.md"
requires-python = ">=3.11"
Expand Down
11 changes: 11 additions & 0 deletions tests/data/valid/scenarios/native/yambs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ cflag_groups:
extra_dist: [extra]
extra_sources: [src_extra]

uf2_family: RP2040

project:
name: yambs
github:
Expand All @@ -18,12 +20,21 @@ variants:
rando_variant:
enabled: false

debug:
suffix: &gcc_version "-13"
targets: [apps, lib, uf2s]

opt:
suffix: *gcc_version

clang:
cflag_groups: [debug]
suffix: &clang_version "-17"

clang-opt:
extra_cflags: [--coverage]
cflag_groups: [opt]
suffix: *clang_version

dependencies:
- github: {repo: yambs-sample, owner: *self}
Expand Down
4 changes: 2 additions & 2 deletions yambs/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# =====================================
# generator=datazen
# version=3.1.4
# hash=ec366500d47c9484008309e85a10fb06
# hash=cb069480d4a43d400275c8e17aa46c39
# =====================================

"""
Expand All @@ -10,4 +10,4 @@

DESCRIPTION = "Yet another meta build-system."
PKG_NAME = "yambs"
VERSION = "2.7.5"
VERSION = "2.8.0"
4 changes: 4 additions & 0 deletions yambs/data/schemas/Native.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,7 @@ properties:
patternProperties:
"^[a-zA-Z0-9-_.]+$":
$ref: package://yambs/schemas/Variant.yaml

uf2_family:
type: string
default: ""
14 changes: 14 additions & 0 deletions yambs/data/templates/native_rules.ninja.j2
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,20 @@ ldflags = $common_ldflags $variant_ldflags
rule link
command = $ld $cflags -Wl,-Map=$out.map $in $ldflags -o $out

rule bin
command = ${toolchain_prefix}objcopy -O binary $in $out

rule hex
command = ${toolchain_prefix}objcopy -O ihex $in $out

rule dump
command = ${toolchain_prefix}objdump -D $in > $out
{% if uf2_family %}

rule uf2
command = mbs uf2conv -f {{uf2_family}} -o $out $in
{% endif %}

rule ar
command = ar rcs $out $in

Expand Down
61 changes: 51 additions & 10 deletions yambs/environment/native.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,38 @@ def write_static_library_rule(

return lib

def _write_app_phony_targets(
self, stream: TextIO, elfs: Dict[Path, Path], uf2_family: str = None
) -> None:
"""Write phony targets for all variants."""

elfs_list = list(elfs.values())

if elfs_list:
line = "build ${variant}_apps: phony "
offset = " " * len(line)

stream.write(line + str(elfs_list[0]))
for elf in elfs_list[1:]:
write_continuation(stream, offset)
stream.write(str(elf))
stream.write(linesep)

if uf2_family:
# Create uf2 phony.
line = "build ${variant}_uf2s: phony "
offset = " " * len(line)

uf2s = [x.with_suffix(".uf2") for x in elfs_list]

stream.write(line + str(uf2s[0]))
for elf in uf2s[1:]:
write_continuation(stream, offset)
stream.write(str(elf))
stream.write(linesep)

def write_app_rules(
self, stream: TextIO, outputs: Set[Path]
self, stream: TextIO, outputs: Set[Path], uf2_family: str = None
) -> Dict[Path, Path]:
"""Write app rules."""

Expand Down Expand Up @@ -168,10 +198,23 @@ def write_app_rules(

stream.write(linesep + linesep)

line = "build ${variant}_apps: phony "
offset = " " * len(line)
# Write rules for other kinds of outputs.
for output in ["bin", "hex", "dump"]:
stream.write(
f"build {elf.with_suffix('.' + output)}: {output} {elf}"
)
stream.write(linesep)

if uf2_family:
stream.write(
(
f"build {elf.with_suffix('.uf2')}: "
f"uf2 {elf.with_suffix('.hex')}"
)
)
stream.write(linesep)

elfs_list = list(elfs.values())
stream.write(linesep)

# Add a phony target for creating a static library.
if outputs:
Expand All @@ -182,11 +225,7 @@ def write_app_rules(
+ linesep
)

stream.write(line + str(elfs_list[0]))
for elf in elfs_list[1:]:
write_continuation(stream, offset)
stream.write(str(elf))
stream.write(linesep)
self._write_app_phony_targets(stream, elfs, uf2_family=uf2_family)

return elfs

Expand Down Expand Up @@ -279,7 +318,9 @@ def generate(self, sources_only: bool = False) -> None:
path = self.config.ninja_root.joinpath("apps.ninja")
with self.log_time("Write '%s'", path):
with path.open("w") as path_fd:
elfs = self.write_app_rules(path_fd, outputs)
elfs = self.write_app_rules(
path_fd, outputs, self.config.data.get("uf2_family")
)

# Render format file.
render_format(
Expand Down

0 comments on commit d4cfd5e

Please sign in to comment.