-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
242 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
use_flake() { | ||
watch_file flake.nix | ||
watch_file flake.lock | ||
eval "$(nix print-dev-env --profile "$(direnv_layout_dir)/flake-profile")" | ||
} | ||
|
||
use flake | ||
|
||
watch_file './site_scons/env.py' | ||
eval $(./site_scons/env.py --export) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,6 @@ runs: | |
steps: | ||
- uses: DeterminateSystems/nix-installer-action@v6 | ||
- uses: DeterminateSystems/magic-nix-cache-action@v2 | ||
- uses: HatsuneMiku3939/[email protected] | ||
with: | ||
direnvVersion: 2.32.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import argparse | ||
import json | ||
import os | ||
import shlex | ||
import typing | ||
|
||
|
||
_CARGO_HOME = '.cargo' | ||
_IDF_BUILD = '.esp-idf' | ||
_IDF_TOOLS_PATH = '.espressif' | ||
_VIRTUAL_ENV = '.venv' | ||
|
||
|
||
DIRENV_INSTALLED: typing.Final[dict[str, str]] = { | ||
f'DIRENV_INSTALLED_{key}': f'{value}/.direnv.installed' | ||
for key, value in { | ||
'CRATES': _CARGO_HOME, | ||
'IDF_TOOLS': _IDF_TOOLS_PATH, | ||
'PYTHON_REQUIREMENTS': _VIRTUAL_ENV, | ||
'SCONS_ESP_IDF_ENVIRONMENT': _IDF_BUILD, | ||
}.items() | ||
} | ||
|
||
|
||
PATHS: typing.Final[dict[str, str]] = { | ||
key: os.path.abspath(value) | ||
for key, value in { | ||
**DIRENV_INSTALLED, | ||
'CARGO_HOME': _CARGO_HOME, | ||
'IDF_BUILD': _IDF_BUILD, | ||
'IDF_BUILD_SCONS_ESP32S3': f'{_IDF_BUILD}/scons/esp32s3.json', | ||
'IDF_PATH': 'lib/esp-idf', | ||
'IDF_TOOLS_PATH': _IDF_TOOLS_PATH, | ||
'REPO_ROOT': '.', | ||
'VIRTUAL_ENV': _VIRTUAL_ENV, | ||
}.items() | ||
} | ||
|
||
|
||
ENV: typing.Final[dict[str, str]] = { | ||
**PATHS, | ||
'CMAKE_GENERATOR': 'Ninja', | ||
'IDF_TARGETS': 'esp32s3', | ||
'VIRTUAL_ENV_DISABLE_PROMPT': 'true', | ||
} | ||
|
||
|
||
def idf(env, target: str): | ||
env = env.Clone() | ||
|
||
with open(PATHS[f'IDF_BUILD_SCONS_{target.upper()}']) as f: | ||
idf = json.load(f) | ||
|
||
env.AppendUnique( | ||
CPPPATH=idf['includes'], | ||
CPPDEFINES=idf['defines'], | ||
CCFLAGS=idf['options'] | ||
+ idf['optimization'] | ||
+ idf['debug'] | ||
+ idf['march'] | ||
+ idf['std'], | ||
) | ||
|
||
env.PrependENVPath('PATH', idf['path']) | ||
|
||
prefix = idf['prefix'] | ||
|
||
env.Replace( | ||
**{ | ||
key: f'{prefix}{val}' | ||
for key, val in { | ||
'AR': 'ar', | ||
'AS': 'as', | ||
'CC': 'gcc', | ||
'CXX': 'g++', | ||
'RANLIB': 'ranlib', | ||
'SHLINK': 'ld', | ||
}.items() | ||
} | ||
) | ||
|
||
return env | ||
|
||
|
||
if __name__ == '__main__': | ||
parser = argparse.ArgumentParser( | ||
prog='env.py', | ||
description='generate environment variables', | ||
) | ||
|
||
parser.add_argument( | ||
'-e', | ||
'--export', | ||
action='store_true', | ||
) | ||
|
||
args = parser.parse_args() | ||
|
||
export = 'export ' if args.export else '' | ||
|
||
for key, value in ENV.items(): | ||
print(f'{export}{key}={shlex.quote(value)}') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import tomllib | ||
|
||
from schema import ( | ||
Regex, | ||
Schema, | ||
) | ||
|
||
|
||
schema = Schema( | ||
{ | ||
'metadata': { | ||
'name': Regex(r'^[a-z]+$'), | ||
'description': str, | ||
}, | ||
} | ||
) | ||
|
||
|
||
def Component(env, target, config): | ||
with open(config.srcnode().abspath, 'rb') as f: | ||
config = tomllib.load(f) | ||
|
||
assert schema.validate(config) == config | ||
|
||
name = config['metadata']['name'] | ||
|
||
return env.Alias(f'component:{name}', target, '') | ||
|
||
|
||
def generate(env): | ||
if env.Detect('Component'): | ||
return | ||
|
||
env.AddMethod(Component, 'Component') | ||
|
||
|
||
def exists(env): | ||
return env.Detect('Component') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import os | ||
|
||
|
||
OUTPUTS = [ | ||
'bootloader/config/sdkconfig.h', | ||
'bootloader/.bin_timestamp', | ||
'bootloader/bootloader.bin', | ||
'bootloader/bootloader.elf', | ||
'bootloader/bootloader.map', | ||
'bootloader/prefix_map_gdbinit', | ||
'config/sdkconfig.h', | ||
'partition_table/partition-table.bin', | ||
'.bin_timestamp', | ||
'app-flash_args', | ||
'bootloader-flash_args', | ||
'firmware.bin', | ||
'firmware.elf', | ||
'firmware.map', | ||
'flash_app_args', | ||
'flash_args', | ||
'flash_bootloader_args', | ||
'flash_project_args', | ||
'flasher_args.json', | ||
'ldgen_libraries', | ||
'partition-table-flash_args', | ||
'prefix_map_gdbinit', | ||
'x509_crt_bundle.S', | ||
] | ||
|
||
|
||
def EspIdf(env, library, target, *, outdir='esp-idf'): | ||
build = f'{os.environ["IDF_BUILD"]}/march/{target}' | ||
outdir = f'{os.path.dirname(library.abspath)}/{outdir}' | ||
|
||
libprebuilt = ( | ||
f'{os.environ["REPO_ROOT"]}/lib/march/{target}/main/libprebuilt.a' | ||
) | ||
|
||
# since the esp-idf build is shared resource we need to | ||
# lock it while we compile and link with out shared library | ||
actions = [ | ||
f'exec {{LOCKFD}}> {build}/scons.lock', | ||
'echo $$LOCKFD', | ||
'flock --exclusive $$LOCKFD', | ||
f'rm -f {libprebuilt}', | ||
f'ln -s {library.abspath} {libprebuilt}', | ||
f'ninja -C {build}', | ||
f'mkdir -p {outdir}/bootloader', | ||
f'mkdir -p {outdir}/partition_table', | ||
*[f'cp {build}/{output} {outdir}/{output}' for output in OUTPUTS], | ||
'exec {LOCKFD}>&-', | ||
] | ||
|
||
actions = ' && '.join(actions) | ||
|
||
out = env.Command( | ||
[f'{outdir}/{output}' for output in OUTPUTS], library, actions | ||
) | ||
|
||
return out | ||
|
||
|
||
def generate(env): | ||
if env.Detect('EspIdf'): | ||
return | ||
|
||
env.AddMethod(EspIdf, 'EspIdf') | ||
|
||
|
||
def exists(env): | ||
return env.Detect('EspIdf') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
def Phony(env, target, action): | ||
return env.AlwaysBuild(env.Alias(target, [], action)) | ||
|
||
|
||
def generate(env): | ||
if env.Detect('Phony'): | ||
return | ||
|
||
env.AddMethod(Phony, 'Phony') | ||
|
||
|
||
def exists(env): | ||
return env.Detect('Phony') |