1# Copyright 2020 The Pigweed Authors 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); you may not 4# use this file except in compliance with the License. You may obtain a copy of 5# the License at 6# 7# https://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12# License for the specific language governing permissions and limitations under 13# the License. 14 15import("//build_overrides/pigweed.gni") 16import("//build_overrides/pigweed_environment.gni") 17 18declare_args() { 19 # Enable/disable Arduino builds via group("arduino"). 20 # Set to the full path of where cores are installed. 21 pw_arduino_build_CORE_PATH = "" 22 23 # Expected args for an Arduino build: 24 pw_arduino_build_CORE_NAME = "" 25 26 # TODO(tonymd): "avr/1.58.1" here should match the folders in this dir: 27 # "../third_party/arduino/cores/$pw_arduino_build_CORE_NAME/hardware/*") 28 # For teensy: "avr/1.58.1", for adafruit-samd: "samd/1.6.2" 29 pw_arduino_build_PACKAGE_NAME = "" 30 pw_arduino_build_BOARD = "" 31 32 # Menu options should be a list of strings. 33 pw_arduino_build_MENU_OPTIONS = [] 34} 35 36if (pw_arduino_build_CORE_PATH != "") { 37 # Check that enough pw_arduino_build_* args are set to find and use a core. 38 _required_args_message = 39 "The following build args must all be set: " + 40 "pw_arduino_build_CORE_PATH, pw_arduino_build_CORE_NAME, " + 41 "pw_arduino_build_PACKAGE_NAME." 42 assert(pw_arduino_build_CORE_NAME != "", 43 "Missing 'pw_arduino_build_CORE_NAME' build arg. " + 44 _required_args_message) 45 assert(pw_arduino_build_PACKAGE_NAME != "", 46 "Missing 'pw_arduino_build_PACKAGE_NAME' build arg. " + 47 _required_args_message) 48 49 _arduino_selected_core_path = 50 rebase_path("$pw_arduino_build_CORE_PATH/$pw_arduino_build_CORE_NAME", 51 root_build_dir) 52 53 arduino_builder_script = 54 get_path_info("py/pw_arduino_build/__main__.py", "abspath") 55 56 # Check pw_arduino_build_BOARD is set 57 assert(pw_arduino_build_BOARD != "", 58 "pw_arduino_build_BOARD build arg not set. " + 59 "To see supported boards run: " + 60 "arduino_builder --arduino-package-path " + 61 _arduino_selected_core_path + " --arduino-package-name " + 62 pw_arduino_build_PACKAGE_NAME + " list-boards") 63 64 arduino_core_library_path = "$_arduino_selected_core_path/hardware/" + 65 "$pw_arduino_build_PACKAGE_NAME/libraries" 66 67 arduino_global_args = [ 68 "--arduino-package-path", 69 _arduino_selected_core_path, 70 "--arduino-package-name", 71 pw_arduino_build_PACKAGE_NAME, 72 ] 73 74 if (defined(pw_env_setup_CIPD_PIGWEED)) { 75 _compiler_path_override = 76 rebase_path(pw_env_setup_CIPD_PIGWEED + "/bin", root_build_dir) 77 78 arduino_global_args += [ 79 "--compiler-path-override", 80 _compiler_path_override, 81 ] 82 } 83 84 arduino_global_args += [ 85 # Save config files to "out/arduino_debug/gen/arduino_builder_config.json" 86 "--config-file", 87 rebase_path(root_gen_dir, root_build_dir) + "/arduino_builder_config.json", 88 "--save-config", 89 ] 90 91 arduino_board_args = [ 92 "--build-path", 93 ".", 94 "--board", 95 pw_arduino_build_BOARD, 96 ] 97 if (pw_arduino_build_MENU_OPTIONS != []) { 98 arduino_board_args += [ "--menu-options" ] 99 arduino_board_args += pw_arduino_build_MENU_OPTIONS 100 } 101 102 arduino_show_command_args = arduino_global_args + [ 103 "show", 104 "--delimit-with-newlines", 105 ] + arduino_board_args 106 107 arduino_run_command_args = 108 arduino_global_args + [ "run" ] + arduino_board_args 109} 110