Skip to content

Commit

Permalink
Merge pull request #58 from vkottler/dev/2.4.0
Browse files Browse the repository at this point in the history
2.4.0 - Better handling for linker flags
  • Loading branch information
vkottler authored Aug 6, 2023
2 parents f2cacde + edce389 commit 8f6261c
Show file tree
Hide file tree
Showing 20 changed files with 70 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ jobs:
- run: |
mk python-release owner=vkottler \
repo=yambs version=2.3.3
repo=yambs version=2.4.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.3
hash=605f8c7be702e2c1acaa6ff990953e10
hash=56e5498dfc3e0d2dbd23a5dfbfe11761
=====================================
-->

# yambs ([2.3.3](https://pypi.org/project/yambs/))
# yambs ([2.4.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
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: 3
patch: 3
minor: 4
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.3.3"
version = "2.4.0"
description = "Yet another meta build-system."
readme = "README.md"
requires-python = ">=3.11"
Expand Down
2 changes: 1 addition & 1 deletion tests/commands/test_native.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ def test_native_command_basic():
# Try to build (if we can).
# Re-enable this when we fix the third party script.
if platform == "linux" and which("ninja"):
run("ninja", check=True)
run(["ninja", "all"], check=True)
1 change: 1 addition & 0 deletions tests/data/valid/scenarios/native/src/apps/c/app3.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ int main(void) {
a *= 2.0f;
a /= 2.0f;
}
(void)a;

return 0;
}
1 change: 1 addition & 0 deletions tests/data/valid/scenarios/native/src/apps/c/app4.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ int main(void) {
a *= 2.0f;
a /= 2.0f;
}
(void)a;

return 0;
}
1 change: 1 addition & 0 deletions tests/data/valid/scenarios/native/src/apps/c/test_app3.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ int main(void) {
a *= 2.0f;
a /= 2.0f;
}
(void)a;

return 0;
}
1 change: 1 addition & 0 deletions tests/data/valid/scenarios/native/src/apps/c/test_app4.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ int main(void) {
a *= 2.0f;
a /= 2.0f;
}
(void)a;

return 0;
}
1 change: 1 addition & 0 deletions tests/data/valid/scenarios/native/src/common/sample2.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ void sample2_method(void) {
for (int i = 0; i < 2000; i++) {
a *= 4;
}
(void)a;
}
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.3
# hash=f04ef9d4d6f5ee04feb84ec77c850330
# hash=97870f506d5d2f9b5b8e3527f76efa07
# =====================================

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

DESCRIPTION = "Yet another meta build-system."
PKG_NAME = "yambs"
VERSION = "2.3.3"
VERSION = "2.4.0"
6 changes: 5 additions & 1 deletion yambs/data/native.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ cflag_groups:

# Instrument builds for coverage and other analysis.
debug: [-Og, -g, --coverage]
opt: [-O2, -s]
opt: [-O2]
asan: [-fsanitize=address]
msan: [-fsanitize=memory]

ldflag_groups:
opt: [-s]

variants:

debug:
Expand All @@ -27,6 +30,7 @@ variants:

clang-opt:
cflag_groups: [opt]
ldflag_groups: [opt]
cc: clang
cxx: clang++
ld: clang++
4 changes: 3 additions & 1 deletion yambs/data/schemas/Native.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ properties:
items:
type: string

cflag_groups:
cflag_groups: &flag_groups
type: object
additionalProperties: false
patternProperties:
Expand All @@ -25,6 +25,8 @@ properties:
items:
type: string

ldflag_groups: *flag_groups

variants:
type: object
additionalProperties: false
Expand Down
4 changes: 0 additions & 4 deletions yambs/data/schemas/Toolchain.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ properties:
type: string
default: ""

suffix:
type: string
default: ""

root:
type: string
default: "./toolchains/$toolchain/out/bin"
6 changes: 6 additions & 0 deletions yambs/data/schemas/Variant.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ properties:
items:
type: string

ldflag_groups:
type: array
default: []
items:
type: string

targets:
type: array
default: [apps, lib]
6 changes: 6 additions & 0 deletions yambs/data/schemas/toolchain_common.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,9 @@ properties:
default: []
items:
type: string

extra_ldflags:
type: array
default: []
items:
type: string
3 changes: 2 additions & 1 deletion yambs/data/templates/native_rules.ninja.j2
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ rule cxx
command = $cxx -MD -MF $out.d $cflags -std=$cxx_standard -c $in -o $out
{% if common_ldflags %}

ldflags ={% for flag in common_ldflags %} {{flag}}{% endfor %}
common_ldflags ={% for flag in common_ldflags %} {{flag}}{% endfor %}

{% endif %}
ldflags = $common_ldflags $variant_ldflags

rule link
command = $ld $cflags -Wl,-Map=$out.map $in $ldflags -o $out
Expand Down
6 changes: 5 additions & 1 deletion yambs/data/templates/variant.ninja.j2
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@ cxx_standard = {{cxx_standard}}
cc = {{cc}}{{suffix}}
cxx = {{cxx}}{{suffix}}
ld = {{ld}}{{suffix}}

{% if extra_cflags %}

variant_cflags ={% for flag in extra_cflags %} {{flag}}{% endfor %}
{% endif %}
{% if extra_ldflags %}

variant_ldflags ={% for flag in extra_ldflags %} {{flag}}{% endfor %}
{% endif %}


include $include_dir/rules.ninja
include $include_dir/sources.ninja
include $include_dir/apps.ninja
Expand Down
5 changes: 4 additions & 1 deletion yambs/environment/native.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,10 @@ def generate(self, sources_only: bool = False) -> None:

# Render templates.
generate_variants(
self.jinja, self.config, self.config.data["cflag_groups"]
self.jinja,
self.config,
self.config.data["cflag_groups"],
self.config.data["ldflag_groups"],
)
self.render(self.config.root, "build.ninja")
for template in ["all", "rules"]:
Expand Down
38 changes: 25 additions & 13 deletions yambs/generate/variants.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,47 +13,59 @@
from yambs.config.common import CommonConfig
from yambs.generate.common import render_template

FlagGroups = Dict[str, List[str]]


@contextmanager
def modified_variant_data(
name: str, data: Dict[str, Any], cflag_groups: Dict[str, List[str]]
name: str,
data: Dict[str, Any],
cflag_groups: FlagGroups,
ldflag_groups: FlagGroups,
) -> Iterator[None]:
"""
Ensure that cflag groups are processed, and that the variant has access to
its name while rendering.
"""

orig = []
if "extra_cflags" in data:
orig = data["extra_cflags"]
orig_c = data["extra_cflags"]
orig_ld = data["extra_ldflags"]

# Process cflag groups.
flags = set(orig + cflag_groups.get(name, []))
for group in data["cflag_groups"]:
flags |= set(cflag_groups[group])
# Process cflag groups.
flags = set(orig_c + cflag_groups.get(name, []))
for group in data["cflag_groups"]:
flags |= set(cflag_groups[group])
data["extra_cflags"] = flags

data["extra_cflags"] = flags
# Process ldflag groups.
flags = set(orig_ld + ldflag_groups.get(name, []))
for group in data["ldflag_groups"]:
flags |= set(ldflag_groups[group])
data["extra_ldflags"] = flags

# Add other useful data.
data["name"] = name

yield

# Restore original data.
del data["name"]
if "extra_cflags" in data:
data["extra_cflags"] = orig
data["extra_cflags"] = orig_c
data["extra_ldflags"] = orig_ld


def generate(
jinja: Environment,
config: CommonConfig,
cflag_groups: Dict[str, List[str]],
cflag_groups: FlagGroups,
ldflag_groups: FlagGroups,
) -> None:
"""Generate variant-related ninja files."""

for name, data in config.data["variants"].items():
variants_root = config.ninja_root.joinpath("variants", name)
variants_root.mkdir(parents=True, exist_ok=True)
with modified_variant_data(name, data, cflag_groups):
with modified_variant_data(name, data, cflag_groups, ldflag_groups):
render_template(
jinja,
variants_root,
Expand Down

0 comments on commit 8f6261c

Please sign in to comment.