diff --git a/lambda/app.rb b/lambda/app.rb index 8c7a697352c..05194be38f2 100644 --- a/lambda/app.rb +++ b/lambda/app.rb @@ -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 diff --git a/lambda/compiler.rb b/lambda/compiler.rb index 94fc7230e18..068a4dcd47e 100644 --- a/lambda/compiler.rb +++ b/lambda/compiler.rb @@ -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 diff --git a/lambda/web_app.rb b/lambda/web_app.rb index 6af1b0c12f7..2439babfcc6 100644 --- a/lambda/web_app.rb +++ b/lambda/web_app.rb @@ -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' diff --git a/nix/zmk.nix b/nix/zmk.nix index 37144fe075a..1bb5395d668 100644 --- a/nix/zmk.nix +++ b/nix/zmk.nix @@ -4,6 +4,7 @@ , board ? "glove80_lh" , shield ? null , keymap ? null +, kconfig ? null }: @@ -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 ]; diff --git a/release.nix b/release.nix index 26233b30198..a9dfdaee91c 100644 --- a/release.nix +++ b/release.nix @@ -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} @@ -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