Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 4f31141

Browse files
committedMar 29, 2023
[WIP] Support passing kconfig settings through to the build process
1 parent bf7bcde commit 4f31141

File tree

5 files changed

+38
-9
lines changed

5 files changed

+38
-9
lines changed
 

‎lambda/app.rb

+10-1
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,18 @@ def self.process(event:, context:)
3737
return error(status: 400, message: 'Invalid Base64 in keymap input')
3838
end
3939

40+
if event.has_key?('kconfig')
41+
kconfig_data =
42+
begin
43+
Base64.strict_decode64(event['kconfig'])
44+
rescue ArgumentError
45+
return error(status: 400, message: 'Invalid Base64 in kconfig input')
46+
end
47+
end
48+
4049
result, log =
4150
begin
42-
Compiler.new.compile(keymap_data)
51+
Compiler.new.compile(keymap_data, kconfig_data)
4352
rescue Compiler::CompileError => e
4453
return error(status: e.status, message: e.message, detail: e.log)
4554
end

‎lambda/compiler.rb

+9-4
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,20 @@ def initialize(message, status: 400, log:)
1515
end
1616
end
1717

18-
def compile(keymap_data)
18+
def compile(keymap_data, kconfig_data)
1919
in_build_dir do
20-
File.open('build.keymap', 'w') do |io|
21-
io.write(keymap_data)
20+
compile_command = ['compileZmk', './build.keymap']
21+
22+
File.open('build.keymap', 'w') { |io| io.write(keymap_data) }
23+
24+
if kconfig_data
25+
File.open('build.conf', 'w') { |io| io.write(kconfig_data) }
26+
compile_command << './build.conf'
2227
end
2328

2429
compile_output = nil
2530

26-
IO.popen(['compileZmk', './build.keymap'], err: [:child, :out]) do |io|
31+
IO.popen(compile_command, err: [:child, :out]) do |io|
2732
compile_output = io.read
2833
end
2934

‎lambda/web_app.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def json_body(hash)
1616
post '/api/compile' do
1717
request.body.rewind
1818
keymap_data = request.body.read
19-
result, log = Compiler.new.compile(keymap_data)
19+
result, log = Compiler.new.compile(keymap_data, nil)
2020

2121
status 200
2222
content_type 'application/octet-stream'

‎nix/zmk.nix

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
, board ? "glove80_lh"
55
, shield ? null
66
, keymap ? null
7+
, kconfig ? null
78
}:
89

910

@@ -92,7 +93,8 @@ stdenvNoCC.mkDerivation {
9293
"-DZEPHYR_MODULES=${lib.concatStringsSep ";" zephyrModuleDeps}"
9394
] ++
9495
(lib.optional (shield != null) "-DSHIELD=${shield}") ++
95-
(lib.optional (keymap != null) "-DKEYMAP_FILE=${keymap}");
96+
(lib.optional (keymap != null) "-DKEYMAP_FILE=${keymap}") ++
97+
(lib.optional (kconfig != null) "-DCONF_FILE=${kconfig}");
9698

9799
nativeBuildInputs = [ cmake ninja python dtc gcc-arm-embedded ];
98100
buildInputs = [ zephyr ];

‎release.nix

+15-2
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,25 @@ let
5656
set -eo pipefail
5757
5858
if [ ! -f "$1" ]; then
59-
echo "Usage: compileZmk [file.keymap]" >&2
59+
echo "Error: Missing keymap file" >&2
60+
echo "Usage: compileZmk file.keymap [file.conf]" >&2
6061
exit 1
6162
fi
6263
6364
KEYMAP="$(${realpath_coreutils}/bin/realpath $1)"
6465
66+
if [ -z "''${2+x}" ]; then
67+
KCONFIG=
68+
else
69+
if [ ! -f "$2" ]; then
70+
echo "Error: Missing kconfig file" >&2
71+
echo "Usage: compileZmk file.keymap [file.conf]" >&2
72+
exit 1
73+
fi
74+
75+
KCONFIG="$(${realpath_coreutils}/bin/realpath $2)"
76+
fi
77+
6578
export PATH=${lib.makeBinPath (with pkgs; zmk'.nativeBuildInputs ++ [ ccache ])}:$PATH
6679
export CMAKE_PREFIX_PATH=${zephyr}
6780
@@ -71,7 +84,7 @@ let
7184
7285
if [ -n "$DEBUG" ]; then ccache -z; fi
7386
74-
cmake -G Ninja -S ${zmk'.src}/app ${lib.escapeShellArgs zmk'.cmakeFlags} "-DUSER_CACHE_DIR=/tmp/.cache" "-DKEYMAP_FILE=$KEYMAP" -DBOARD=glove80_lh
87+
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
7588
7689
ninja
7790

0 commit comments

Comments
 (0)
Please sign in to comment.