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