Skip to content

Commit

Permalink
Support passing kconfig settings through to the build process
Browse files Browse the repository at this point in the history
Adds a new `kconfig` parameter to the firmware builder lambda function
  • Loading branch information
chrisandreae committed May 19, 2023
1 parent 2a7f8d2 commit 3e8f475
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 9 deletions.
11 changes: 10 additions & 1 deletion lambda/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,18 @@ def self.process(event:, context:)
return error(status: 400, message: 'Invalid Base64 in keymap input')
end

if event.has_key?('kconfig')
kconfig_data =
begin
Base64.strict_decode64(event['kconfig'])
rescue ArgumentError
return error(status: 400, message: 'Invalid Base64 in kconfig input')
end
end

result, log =
begin
Compiler.new.compile(keymap_data)
Compiler.new.compile(keymap_data, kconfig_data)
rescue Compiler::CompileError => e
return error(status: e.status, message: e.message, detail: e.log)
end
Expand Down
13 changes: 9 additions & 4 deletions lambda/compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,20 @@ def initialize(message, status: 400, log:)
end
end

def compile(keymap_data)
def compile(keymap_data, kconfig_data)
in_build_dir do
File.open('build.keymap', 'w') do |io|
io.write(keymap_data)
compile_command = ['compileZmk', './build.keymap']

File.open('build.keymap', 'w') { |io| io.write(keymap_data) }

if kconfig_data
File.open('build.conf', 'w') { |io| io.write(kconfig_data) }
compile_command << './build.conf'
end

compile_output = nil

IO.popen(['compileZmk', './build.keymap'], err: [:child, :out]) do |io|
IO.popen(compile_command, err: [:child, :out]) do |io|
compile_output = io.read
end

Expand Down
2 changes: 1 addition & 1 deletion lambda/web_app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def json_body(hash)
post '/api/compile' do
request.body.rewind
keymap_data = request.body.read
result, log = Compiler.new.compile(keymap_data)
result, log = Compiler.new.compile(keymap_data, nil)

status 200
content_type 'application/octet-stream'
Expand Down
4 changes: 3 additions & 1 deletion nix/zmk.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
, board ? "glove80_lh"
, shield ? null
, keymap ? null
, kconfig ? null
}:


Expand Down Expand Up @@ -92,7 +93,8 @@ stdenvNoCC.mkDerivation {
"-DZEPHYR_MODULES=${lib.concatStringsSep ";" zephyrModuleDeps}"
] ++
(lib.optional (shield != null) "-DSHIELD=${shield}") ++
(lib.optional (keymap != null) "-DKEYMAP_FILE=${keymap}");
(lib.optional (keymap != null) "-DKEYMAP_FILE=${keymap}") ++
(lib.optional (kconfig != null) "-DCONF_FILE=${kconfig}");

nativeBuildInputs = [ cmake ninja python dtc gcc-arm-embedded ];
buildInputs = [ zephyr ];
Expand Down
17 changes: 15 additions & 2 deletions release.nix
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,25 @@ let
set -eo pipefail
if [ ! -f "$1" ]; then
echo "Usage: compileZmk [file.keymap]" >&2
echo "Error: Missing keymap file" >&2
echo "Usage: compileZmk file.keymap [file.conf]" >&2
exit 1
fi
KEYMAP="$(${realpath_coreutils}/bin/realpath $1)"
if [ -z "''${2+x}" ]; then
KCONFIG=
else
if [ ! -f "$2" ]; then
echo "Error: Missing kconfig file" >&2
echo "Usage: compileZmk file.keymap [file.conf]" >&2
exit 1
fi
KCONFIG="$(${realpath_coreutils}/bin/realpath $2)"
fi
export PATH=${lib.makeBinPath (with pkgs; zmk'.nativeBuildInputs ++ [ ccache ])}:$PATH
export CMAKE_PREFIX_PATH=${zephyr}
Expand All @@ -71,7 +84,7 @@ let
if [ -n "$DEBUG" ]; then ccache -z; fi
cmake -G Ninja -S ${zmk'.src}/app ${lib.escapeShellArgs zmk'.cmakeFlags} "-DUSER_CACHE_DIR=/tmp/.cache" "-DKEYMAP_FILE=$KEYMAP" -DBOARD=glove80_lh
cmake -G Ninja -S ${zmk'.src}/app ${lib.escapeShellArgs zmk'.cmakeFlags} "-DUSER_CACHE_DIR=/tmp/.cache" "-DKEYMAP_FILE=$KEYMAP" "-DCONF_FILE=$KCONFIG" -DBOARD=glove80_lh
ninja
Expand Down

0 comments on commit 3e8f475

Please sign in to comment.