[gn] introduce build_root variable (#4352)

* [gn] introduce build_root variable

* [nrfconnect] build from CHIP root directory

* [pigweed] bump version

* [nrfconnect] ensure the minimum gn version is installed

* Restyled by gn

Co-authored-by: Restyled.io <commits@restyled.io>
diff --git a/.gn b/.gn
index 19c0501..e3a67f1 100644
--- a/.gn
+++ b/.gn
@@ -12,14 +12,15 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import("//build_overrides/build.gni")
+import("//build_overrides/pigweed.gni")
+
 # The location of the build configuration file.
-buildconfig = "//build/config/BUILDCONFIG.gn"
+buildconfig = "${build_root}/config/BUILDCONFIG.gn"
 
 # CHIP uses angle bracket includes.
 check_system_includes = true
 
-import("//build_overrides/pigweed.gni")
-
 script_executable = "python3"
 
 default_args = {
diff --git a/BUILD.gn b/BUILD.gn
index 653ea45..ba676c6 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -12,20 +12,22 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import("//build_overrides/build.gni")
 import("//build_overrides/chip.gni")
 import("//build_overrides/mbedtls.gni")
 import("//build_overrides/nlassert.gni")
 import("//build_overrides/nlio.gni")
 import("//build_overrides/nlunit_test.gni")
 import("//build_overrides/pigweed.gni")
+
 import("//src/platform/device.gni")
 import("$dir_pw_build/python.gni")
 
 # This build file should not be used in superproject builds.
 assert(chip_root == "//")
 
-import("${chip_root}/build/chip/tests.gni")
-import("${chip_root}/build/chip/tools.gni")
+import("${build_root}/chip/tests.gni")
+import("${build_root}/chip/tools.gni")
 
 if (current_toolchain != "${dir_pw_toolchain}/dummy:dummy") {
   declare_args() {
@@ -115,7 +117,7 @@
   }
 } else {
   # This is the unified build. Configure various real toolchains.
-  import("${chip_root}/build/chip/chip_build.gni")
+  import("${build_root}/chip/chip_build.gni")
   declare_args() {
     # Set this to false to disable all builds by default.
     enable_default_builds = true
@@ -179,13 +181,13 @@
 
   if (enable_host_clang_build) {
     chip_build("host_clang") {
-      toolchain = "//build/toolchain/host:${host_os}_${host_cpu}_clang"
+      toolchain = "${build_root}/toolchain/host:${host_os}_${host_cpu}_clang"
     }
   }
 
   if (enable_host_gcc_build) {
     chip_build("host_gcc") {
-      toolchain = "//build/toolchain/host:${host_os}_${host_cpu}_gcc"
+      toolchain = "${build_root}/toolchain/host:${host_os}_${host_cpu}_gcc"
     }
   }
 
@@ -197,19 +199,19 @@
 
   if (enable_android_builds) {
     chip_build("android_arm") {
-      toolchain = "//build/toolchain/android:android_arm"
+      toolchain = "${build_root}/toolchain/android:android_arm"
     }
 
     chip_build("android_arm64") {
-      toolchain = "//build/toolchain/android:android_arm64"
+      toolchain = "${build_root}/toolchain/android:android_arm64"
     }
 
     chip_build("android_x64") {
-      toolchain = "//build/toolchain/android:android_x64"
+      toolchain = "${build_root}/toolchain/android:android_x64"
     }
 
     chip_build("android_x86") {
-      toolchain = "//build/toolchain/android:android_x86"
+      toolchain = "${build_root}/toolchain/android:android_x86"
     }
   }
 
diff --git a/build/chip/buildconfig_header.gni b/build/chip/buildconfig_header.gni
index d9d3b4f..08ec187 100644
--- a/build/chip/buildconfig_header.gni
+++ b/build/chip/buildconfig_header.gni
@@ -101,6 +101,7 @@
 #     ]
 #   }
 
+import("//build_overrides/build.gni")
 import("//build_overrides/chip.gni")
 
 template("buildconfig_header") {
@@ -108,7 +109,7 @@
   gen_target_name = "gen_${target_name}"
 
   action(gen_target_name) {
-    script = "${chip_root}/build/chip/write_buildconfig_header.py"
+    script = "${build_root}/chip/write_buildconfig_header.py"
 
     if (defined(invoker.header_dir)) {
       header_file = "${invoker.header_dir}/${invoker.header}"
diff --git a/build/chip/chip_build.gni b/build/chip/chip_build.gni
index 1521f58..d72e304 100644
--- a/build/chip/chip_build.gni
+++ b/build/chip/chip_build.gni
@@ -12,9 +12,9 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-import("//build_overrides/chip.gni")
+import("//build_overrides/build.gni")
 
-import("${chip_root}/build/chip/tests.gni")
+import("${build_root}/chip/tests.gni")
 
 template("chip_build") {
   _build_name = target_name
diff --git a/build/chip/chip_test.gni b/build/chip/chip_test.gni
index a9970fa..b89749e 100644
--- a/build/chip/chip_test.gni
+++ b/build/chip/chip_test.gni
@@ -12,11 +12,13 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import("//build_overrides/build.gni")
 import("//build_overrides/chip.gni")
 import("//build_overrides/pigweed.gni")
+
 import("$dir_pw_build/python_action.gni")
 
-import("${chip_root}/build/chip/tests.gni")
+import("${build_root}/chip/tests.gni")
 import("${chip_root}/src/platform/device.gni")
 import("${dir_pw_unit_test}/test.gni")
 
diff --git a/build/chip/chip_test_group.gni b/build/chip/chip_test_group.gni
index 4285f59..c87bd39 100644
--- a/build/chip/chip_test_group.gni
+++ b/build/chip/chip_test_group.gni
@@ -12,9 +12,9 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-import("//build_overrides/chip.gni")
+import("//build_overrides/build.gni")
 
-import("${chip_root}/build/chip/tests.gni")
+import("${build_root}/chip/tests.gni")
 
 assert(chip_build_tests)
 
diff --git a/build/chip/chip_test_suite.gni b/build/chip/chip_test_suite.gni
index 3881de9..79678bb 100644
--- a/build/chip/chip_test_suite.gni
+++ b/build/chip/chip_test_suite.gni
@@ -12,10 +12,11 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import("//build_overrides/build.gni")
 import("//build_overrides/chip.gni")
 
-import("${chip_root}/build/chip/chip_test.gni")
-import("${chip_root}/build/chip/tests.gni")
+import("${build_root}/chip/chip_test.gni")
+import("${build_root}/chip/tests.gni")
 import("${dir_pw_unit_test}/test.gni")
 
 assert(chip_build_tests)
diff --git a/build/chip/happy_test.gni b/build/chip/happy_test.gni
index dbc5ef0..01883de 100644
--- a/build/chip/happy_test.gni
+++ b/build/chip/happy_test.gni
@@ -12,9 +12,10 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import("//build_overrides/build.gni")
 import("//build_overrides/chip.gni")
 
-import("${chip_root}/build/chip/tests.gni")
+import("${build_root}/chip/tests.gni")
 
 assert(chip_build_tests)
 assert(chip_enable_happy_tests)
diff --git a/build/chip/java/BUILD.gn b/build/chip/java/BUILD.gn
index a57c64d..21388f7 100644
--- a/build/chip/java/BUILD.gn
+++ b/build/chip/java/BUILD.gn
@@ -12,10 +12,10 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-import("//build_overrides/chip.gni")
+import("//build_overrides/build.gni")
 
-import("//build/config/android/config.gni")
-import("//build/config/android_abi.gni")
+import("${build_root}/config/android/config.gni")
+import("${build_root}/config/android_abi.gni")
 
 # Place a copy of the shared c++ support library in the jni output directory
 # See:
diff --git a/build/chip/java/rules.gni b/build/chip/java/rules.gni
index 2597ec7..8bbd839 100644
--- a/build/chip/java/rules.gni
+++ b/build/chip/java/rules.gni
@@ -12,12 +12,12 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-import("//build_overrides/chip.gni")
+import("//build_overrides/build.gni")
 
-import("//build/config/android/config.gni")
+import("${build_root}/config/android/config.gni")
 
-javac_runner = "${chip_root}/build/chip/java/javac_runner.py"
-jar_runner = "${chip_root}/build/chip/java/jar_runner.py"
+javac_runner = "${build_root}/chip/java/javac_runner.py"
+jar_runner = "${build_root}/chip/java/jar_runner.py"
 
 assert(android_sdk_root != "", "android_sdk_root must be specified")
 
diff --git a/build/chip/linux/BUILD.gn b/build/chip/linux/BUILD.gn
index 60fdb8c..c86f803 100644
--- a/build/chip/linux/BUILD.gn
+++ b/build/chip/linux/BUILD.gn
@@ -12,7 +12,9 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-import("//build/config/linux/pkg_config.gni")
+import("//build_overrides/build.gni")
+
+import("${build_root}/config/linux/pkg_config.gni")
 
 pkg_config("glib") {
   packages = [
diff --git a/build/config/BUILDCONFIG.gn b/build/config/BUILDCONFIG.gn
index 89733cd..0dccc90 100644
--- a/build/config/BUILDCONFIG.gn
+++ b/build/config/BUILDCONFIG.gn
@@ -32,8 +32,8 @@
   current_os = target_os
 }
 
-_chip_overrides = {
-  import("//build_overrides/chip.gni")
+_build_overrides = {
+  import("//build_overrides/build.gni")
 }
 
 _pigweed_overrides = {
@@ -41,7 +41,7 @@
 }
 
 _chip_defaults = {
-  import("//build/config/defaults.gni")
+  import("${_build_overrides.build_root}/config/defaults.gni")
 }
 
 declare_args() {
@@ -51,9 +51,9 @@
 
 if (host_toolchain == "") {
   if (_chip_defaults.is_clang) {
-    host_toolchain = "//build/toolchain/host:${host_os}_${host_cpu}_clang"
+    host_toolchain = "${_build_overrides.build_root}/toolchain/host:${host_os}_${host_cpu}_clang"
   } else {
-    host_toolchain = "//build/toolchain/host:${host_os}_${host_cpu}_gcc"
+    host_toolchain = "${_build_overrides.build_root}/toolchain/host:${host_os}_${host_cpu}_gcc"
   }
 }
 
@@ -65,24 +65,29 @@
   _default_toolchain = "${_pigweed_overrides.dir_pw_toolchain}/dummy"
 } else if (target_os == "freertos") {
   if (target_cpu == "arm") {
-    _default_toolchain = "//build/toolchain/arm_gcc"
+    _default_toolchain = "${_build_overrides.build_root}/toolchain/arm_gcc"
   } else {
     assert(false, "Unsupported target_cpu: ${target_cpu}")
   }
 } else if (target_os == "android") {
   if (current_cpu == "arm") {
-    _default_toolchain = "//build/toolchain/android:android_arm"
+    _default_toolchain =
+        "${_build_overrides.build_root}/toolchain/android:android_arm"
   } else if (current_cpu == "arm64") {
-    _default_toolchain = "//build/toolchain/android:android_arm64"
+    _default_toolchain =
+        "${_build_overrides.build_root}/toolchain/android:android_arm64"
   } else if (current_cpu == "x64") {
-    _default_toolchain = "//build/toolchain/android:android_x64"
+    _default_toolchain =
+        "${_build_overrides.build_root}/toolchain/android:android_x64"
   } else if (current_cpu == "x86") {
-    _default_toolchain = "//build/toolchain/android:android_x86"
+    _default_toolchain =
+        "${_build_overrides.build_root}/toolchain/android:android_x86"
   } else {
     assert(false, "Unsupported target_cpu: ${current_cpu}")
   }
 } else if (target_os == "ios") {
-  _default_toolchain = "//build/toolchain/ios:ios_${target_cpu}"
+  _default_toolchain =
+      "${_build_overrides.build_root}/toolchain/ios:ios_${target_cpu}"
 } else {
   assert(false, "No toolchain specified, please specify custom_toolchain")
 }
diff --git a/build/config/arm.gni b/build/config/arm.gni
index cdc8f57..fc869b1 100644
--- a/build/config/arm.gni
+++ b/build/config/arm.gni
@@ -12,6 +12,8 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import("//build_overrides/build.gni")
+
 if (current_cpu == "arm" || current_cpu == "arm64") {
   declare_args() {
     # Build file to import for ARM defaults.
@@ -20,7 +22,7 @@
 
   if (arm_platform_config == "") {
     if (current_os == "android") {
-      arm_platform_config = "//build/toolchain/android/android_arm.gni"
+      arm_platform_config = "${build_root}/toolchain/android/android_arm.gni"
     }
   }
 
diff --git a/build/config/compiler/BUILD.gn b/build/config/compiler/BUILD.gn
index 4f0009a..d018af5 100644
--- a/build/config/compiler/BUILD.gn
+++ b/build/config/compiler/BUILD.gn
@@ -12,11 +12,11 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-import("//build_overrides/chip.gni")
+import("//build_overrides/build.gni")
 import("//build_overrides/pigweed.gni")
 
-import("//build/config/compiler/compiler.gni")
-import("//build/config/target.gni")
+import("${build_root}/config/compiler/compiler.gni")
+import("${build_root}/config/target.gni")
 
 declare_args() {
   # Enable -Werror. This can be disabled if using a different compiler
@@ -28,9 +28,9 @@
                    (current_cpu == "arm" || current_cpu == "arm64")
 
 if (_is_embedded_arm) {
-  import("//build/config/arm.gni")
+  import("${build_root}/config/arm.gni")
 } else if (current_cpu == "x86" || current_cpu == "x86_64") {
-  import("//build/config/x86.gni")
+  import("${build_root}/config/x86.gni")
 }
 
 config("release") {
diff --git a/build/config/defaults.gni b/build/config/defaults.gni
index a5dddc9..f94fed0 100644
--- a/build/config/defaults.gni
+++ b/build/config/defaults.gni
@@ -12,65 +12,71 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-import("//build_overrides/chip.gni")
+import("//build_overrides/build.gni")
 
-import("//build/config/compiler/compiler.gni")
-import("//build/config/custom_toolchain.gni")
+import("${build_root}/config/compiler/compiler.gni")
+import("${build_root}/config/custom_toolchain.gni")
 
 declare_args() {
   # Default configs for abi.
-  default_configs_abi = [ "//build/config/compiler:abi_default" ]
+  default_configs_abi = [ "${build_root}/config/compiler:abi_default" ]
 
   # Default configs for debugging.
-  default_configs_debug = [ "//build/config/compiler:debug_default" ]
+  default_configs_debug = [ "${build_root}/config/compiler:debug_default" ]
 
   # Default configs for specs.
-  default_configs_specs = [ "//build/config/compiler:specs_default" ]
+  default_configs_specs = [ "${build_root}/config/compiler:specs_default" ]
 
   # Default configs for optimization.
-  default_configs_optimize = [ "//build/config/compiler:optimize_default" ]
+  default_configs_optimize =
+      [ "${build_root}/config/compiler:optimize_default" ]
 
   # Default configs for language.
-  default_configs_std = [ "//build/config/compiler:std_default" ]
+  default_configs_std = [ "${build_root}/config/compiler:std_default" ]
 
   # Defaults configs for symbols.
-  default_configs_symbols = [ "//build/config/compiler:symbols_default" ]
+  default_configs_symbols = [ "${build_root}/config/compiler:symbols_default" ]
 
   # Defaults configs for aliasing.
-  default_configs_aliasing = [ "//build/config/compiler:aliasing_default" ]
+  default_configs_aliasing =
+      [ "${build_root}/config/compiler:aliasing_default" ]
 
   # Defaults configs for size.
-  default_configs_size = [ "//build/config/compiler:size_default" ]
+  default_configs_size = [ "${build_root}/config/compiler:size_default" ]
 
   # Defaults configs for exceptions.
-  default_configs_exceptions = [ "//build/config/compiler:exceptions_default" ]
+  default_configs_exceptions =
+      [ "${build_root}/config/compiler:exceptions_default" ]
 
   # Defaults configs for rtti.
-  default_configs_rtti = [ "//build/config/compiler:rtti_default" ]
+  default_configs_rtti = [ "${build_root}/config/compiler:rtti_default" ]
 
   # Defaults configs for pic.
-  default_configs_pic = [ "//build/config/compiler:pic_default" ]
+  default_configs_pic = [ "${build_root}/config/compiler:pic_default" ]
 
   # Defaults configs for pie.
-  default_configs_pie = [ "//build/config/compiler:pie_default" ]
+  default_configs_pie = [ "${build_root}/config/compiler:pie_default" ]
 
   # Defaults configs for warnings.
-  default_configs_warnings = [ "//build/config/compiler:warnings_default" ]
+  default_configs_warnings =
+      [ "${build_root}/config/compiler:warnings_default" ]
 
   # Defaults cosmetic configs.
-  default_configs_cosmetic = [ "//build/config/compiler:cosmetic_default" ]
+  default_configs_cosmetic =
+      [ "${build_root}/config/compiler:cosmetic_default" ]
 
   # Default configs for runtime library.
-  default_configs_runtime = [ "//build/config/compiler:runtime_default" ]
+  default_configs_runtime = [ "${build_root}/config/compiler:runtime_default" ]
 
   # Defaults sanitizer configs.
-  default_configs_sanitize = [ "//build/config/compiler:sanitize_default" ]
+  default_configs_sanitize =
+      [ "${build_root}/config/compiler:sanitize_default" ]
 
   # Defaults fuzzing configs.
-  default_configs_fuzzing = [ "//build/config/compiler:fuzzing_default" ]
+  default_configs_fuzzing = [ "${build_root}/config/compiler:fuzzing_default" ]
 
   # Defaults target-specific configs.
-  default_configs_target = [ "//build/config/compiler:target_default" ]
+  default_configs_target = [ "${build_root}/config/compiler:target_default" ]
 
   # Extra default configs.
   default_configs_extra = []
diff --git a/build/config/linux/pkg_config.gni b/build/config/linux/pkg_config.gni
index e44bc25..cabb647 100644
--- a/build/config/linux/pkg_config.gni
+++ b/build/config/linux/pkg_config.gni
@@ -47,6 +47,8 @@
 # when doing manual dynamic linking), set:
 #   ignore_libs = true
 
+import("//build_overrides/build.gni")
+
 declare_args() {
   # A pkg-config wrapper to call instead of trying to find and call the right
   # pkg-config directly. Wrappers like this are common in cross-compilation
@@ -59,7 +61,7 @@
   host_pkg_config = ""
 }
 
-pkg_config_script = "//build/config/linux/pkg-config.py"
+pkg_config_script = "${build_root}/config/linux/pkg-config.py"
 
 # Define the args we pass to the pkg-config script for other build files that
 # need to invoke it manually.
diff --git a/build/toolchain/android/android_toolchain.gni b/build/toolchain/android/android_toolchain.gni
index 92151ac..d54d218 100644
--- a/build/toolchain/android/android_toolchain.gni
+++ b/build/toolchain/android/android_toolchain.gni
@@ -12,8 +12,10 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-import("//build/config/android/config.gni")
-import("//build/toolchain/gcc_toolchain.gni")
+import("//build_overrides/build.gni")
+
+import("${build_root}/config/android/config.gni")
+import("${build_root}/toolchain/gcc_toolchain.gni")
 
 template("android_clang_toolchain") {
   _invoker_toolchain_args = invoker.toolchain_args
diff --git a/build/toolchain/arm_gcc/arm_toolchain.gni b/build/toolchain/arm_gcc/arm_toolchain.gni
index c75c276..1e2750c 100644
--- a/build/toolchain/arm_gcc/arm_toolchain.gni
+++ b/build/toolchain/arm_gcc/arm_toolchain.gni
@@ -12,7 +12,9 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-import("//build/toolchain/gcc_toolchain.gni")
+import("//build_overrides/build.gni")
+
+import("${build_root}/toolchain/gcc_toolchain.gni")
 
 template("arm_toolchain") {
   gcc_toolchain(target_name) {
diff --git a/build/toolchain/flashable_executable.gni b/build/toolchain/flashable_executable.gni
index b82e3aa..37e9d0b 100644
--- a/build/toolchain/flashable_executable.gni
+++ b/build/toolchain/flashable_executable.gni
@@ -12,7 +12,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-import("//build_overrides/chip.gni")
+import("//build_overrides/build.gni")
 
 # Convert a binary to a target format using objcopy.
 
@@ -37,7 +37,7 @@
       rebase_path(conversion_input, root_build_dir),
       rebase_path(conversion_output, root_build_dir),
     ]
-    script = "//build/gn_run_binary.py"
+    script = "${build_root}/gn_run_binary.py"
   }
 }
 
diff --git a/build/toolchain/host/BUILD.gn b/build/toolchain/host/BUILD.gn
index 3ef74dc..5f88338 100644
--- a/build/toolchain/host/BUILD.gn
+++ b/build/toolchain/host/BUILD.gn
@@ -13,7 +13,9 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-import("//build/toolchain/gcc_toolchain.gni")
+import("//build_overrides/build.gni")
+
+import("${build_root}/toolchain/gcc_toolchain.gni")
 
 gcc_toolchain("${host_os}_${host_cpu}_gcc") {
   toolchain_args = {
diff --git a/build/toolchain/ios/BUILD.gn b/build/toolchain/ios/BUILD.gn
index 8906d41..8880a98 100644
--- a/build/toolchain/ios/BUILD.gn
+++ b/build/toolchain/ios/BUILD.gn
@@ -13,7 +13,9 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-import("//build/toolchain/gcc_toolchain.gni")
+import("//build_overrides/build.gni")
+
+import("${build_root}/toolchain/gcc_toolchain.gni")
 
 gcc_toolchain("ios_arm") {
   toolchain_args = {
diff --git a/build_overrides/esp32.gni b/build_overrides/build.gni
similarity index 81%
rename from build_overrides/esp32.gni
rename to build_overrides/build.gni
index 3a2252c..6bcce9a 100644
--- a/build_overrides/esp32.gni
+++ b/build_overrides/build.gni
@@ -1,4 +1,4 @@
-# Copyright (c) 2020 Project CHIP Authors
+# Copyright (c) 2021 Project CHIP Authors
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -11,3 +11,8 @@
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.
+
+declare_args() {
+  # Root directory for build files.
+  build_root = "//build"
+}
diff --git a/config/efr32/toolchain/BUILD.gn b/config/efr32/toolchain/BUILD.gn
index 2d72f2e..e296737 100644
--- a/config/efr32/toolchain/BUILD.gn
+++ b/config/efr32/toolchain/BUILD.gn
@@ -12,9 +12,10 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import("//build_overrides/build.gni")
 import("//build_overrides/chip.gni")
 
-import("//build/toolchain/arm_gcc/arm_toolchain.gni")
+import("${build_root}/toolchain/arm_gcc/arm_toolchain.gni")
 
 arm_toolchain("efr32_lock_app") {
   toolchain_args = {
diff --git a/config/esp32/.gn b/config/esp32/.gn
index 5d73f66..2cb77a0 100644
--- a/config/esp32/.gn
+++ b/config/esp32/.gn
@@ -12,8 +12,10 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import("//build_overrides/build.gni")
+
 # The location of the build configuration file.
-buildconfig = "//build/config/BUILDCONFIG.gn"
+buildconfig = "${build_root}/config/BUILDCONFIG.gn"
 
 # CHIP uses angle bracket includes.
 check_system_includes = true
diff --git a/config/esp32/BUILD.gn b/config/esp32/BUILD.gn
index bd9cb0f..d886875 100644
--- a/config/esp32/BUILD.gn
+++ b/config/esp32/BUILD.gn
@@ -15,9 +15,10 @@
 # Options from standalone-chip.mk that differ from configure defaults. These
 # options are used from examples/.
 
+import("//build_overrides/build.gni")
 import("//build_overrides/chip.gni")
 
-import("${chip_root}/build/chip/tests.gni")
+import("${build_root}/chip/tests.gni")
 
 declare_args() {
   chip_build_pw_rpc_lib = false
diff --git a/config/esp32/toolchain/BUILD.gn b/config/esp32/toolchain/BUILD.gn
index 3536980..24641b9 100644
--- a/config/esp32/toolchain/BUILD.gn
+++ b/config/esp32/toolchain/BUILD.gn
@@ -12,9 +12,10 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import("//build_overrides/build.gni")
 import("//build_overrides/chip.gni")
 
-import("//build/toolchain/gcc_toolchain.gni")
+import("${build_root}/toolchain/gcc_toolchain.gni")
 
 declare_args() {
   esp32_ar = ""
diff --git a/config/k32w/toolchain/BUILD.gn b/config/k32w/toolchain/BUILD.gn
index 1bcb0bb..874c49f 100644
--- a/config/k32w/toolchain/BUILD.gn
+++ b/config/k32w/toolchain/BUILD.gn
@@ -12,9 +12,10 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import("//build_overrides/build.gni")
 import("//build_overrides/chip.gni")
 
-import("//build/toolchain/arm_gcc/arm_toolchain.gni")
+import("${build_root}/toolchain/arm_gcc/arm_toolchain.gni")
 
 arm_toolchain("k32w_lock_app") {
   toolchain_args = {
diff --git a/config/mbedtls/toolchain/BUILD.gn b/config/mbedtls/toolchain/BUILD.gn
index c8a586d..d3af441 100644
--- a/config/mbedtls/toolchain/BUILD.gn
+++ b/config/mbedtls/toolchain/BUILD.gn
@@ -12,9 +12,9 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-import("//build_overrides/chip.gni")
+import("//build_overrides/build.gni")
 
-import("//build/toolchain/gcc_toolchain.gni")
+import("${build_root}/toolchain/gcc_toolchain.gni")
 
 gcc_toolchain("${host_os}_${host_cpu}_gcc_mbedtls") {
   toolchain_args = {
diff --git a/config/nrfconnect/chip-gn/.gn b/config/nrfconnect/chip-gn/.gn
index cafc14f..bf81e1e 100644
--- a/config/nrfconnect/chip-gn/.gn
+++ b/config/nrfconnect/chip-gn/.gn
@@ -12,8 +12,11 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import("//build_overrides/build.gni")
+import("//build_overrides/chip.gni")
+
 # The location of the build configuration file.
-buildconfig = "//build/config/BUILDCONFIG.gn"
+buildconfig = "${build_root}/config/BUILDCONFIG.gn"
 
 # CHIP uses angle bracket includes.
 check_system_includes = true
@@ -22,5 +25,5 @@
   target_cpu = "arm"
   target_os = "zephyr"
 
-  import("//args.gni")
+  import("${chip_root}/config/nrfconnect/chip-gn/args.gni")
 }
diff --git a/config/nrfconnect/chip-gn/BUILD.gn b/config/nrfconnect/chip-gn/BUILD.gn
index bf1d8d3..c11b755 100644
--- a/config/nrfconnect/chip-gn/BUILD.gn
+++ b/config/nrfconnect/chip-gn/BUILD.gn
@@ -12,9 +12,10 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import("//build_overrides/build.gni")
 import("//build_overrides/chip.gni")
 
-import("//${chip_root}/build/chip/tests.gni")
+import("${build_root}/chip/tests.gni")
 
 assert(current_os == "zephyr")
 
@@ -23,9 +24,6 @@
   chip_build_pw_rpc_lib = false
 }
 
-group("dummy") {
-}
-
 group("nrfconnect") {
   deps = [ "${chip_root}/src/lib" ]
 
diff --git a/config/nrfconnect/chip-gn/args.gni b/config/nrfconnect/chip-gn/args.gni
index ccee7fe..103e858 100644
--- a/config/nrfconnect/chip-gn/args.gni
+++ b/config/nrfconnect/chip-gn/args.gni
@@ -13,7 +13,6 @@
 # limitations under the License.
 
 import("//build_overrides/chip.gni")
-import("//lib/pw_rpc/pw_rpc.gni")
 
 chip_device_platform = "nrfconnect"
 
@@ -23,5 +22,4 @@
 chip_system_project_config_include = ""
 chip_ble_project_config_include = ""
 
-custom_toolchain = "//toolchain:zephyr"
-mbedtls_target = "//:dummy"
+custom_toolchain = "${chip_root}/config/nrfconnect/chip-gn/toolchain:zephyr"
diff --git a/config/nrfconnect/chip-gn/build b/config/nrfconnect/chip-gn/build
deleted file mode 120000
index d56ed62..0000000
--- a/config/nrfconnect/chip-gn/build
+++ /dev/null
@@ -1 +0,0 @@
-third_party/connectedhomeip/build
\ No newline at end of file
diff --git a/config/nrfconnect/chip-gn/build_overrides b/config/nrfconnect/chip-gn/build_overrides
deleted file mode 120000
index 5140c24..0000000
--- a/config/nrfconnect/chip-gn/build_overrides
+++ /dev/null
@@ -1 +0,0 @@
-../../../examples/build_overrides/
\ No newline at end of file
diff --git a/config/nrfconnect/chip-gn/lib/pw_rpc/pw_rpc.gni b/config/nrfconnect/chip-gn/lib/pw_rpc/pw_rpc.gni
index b1af418..6fcb3c6 100644
--- a/config/nrfconnect/chip-gn/lib/pw_rpc/pw_rpc.gni
+++ b/config/nrfconnect/chip-gn/lib/pw_rpc/pw_rpc.gni
@@ -1,3 +1,17 @@
+# Copyright (c) 2021 Project CHIP Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
 import("//build_overrides/chip.gni")
 import("//build_overrides/pigweed.gni")
 
diff --git a/config/nrfconnect/chip-gn/third_party/connectedhomeip b/config/nrfconnect/chip-gn/third_party/connectedhomeip
deleted file mode 120000
index 11a54ed..0000000
--- a/config/nrfconnect/chip-gn/third_party/connectedhomeip
+++ /dev/null
@@ -1 +0,0 @@
-../../../../
\ No newline at end of file
diff --git a/config/nrfconnect/chip-gn/toolchain/BUILD.gn b/config/nrfconnect/chip-gn/toolchain/BUILD.gn
index f68c283..4f03e45 100644
--- a/config/nrfconnect/chip-gn/toolchain/BUILD.gn
+++ b/config/nrfconnect/chip-gn/toolchain/BUILD.gn
@@ -12,9 +12,9 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-import("//build_overrides/chip.gni")
+import("//build_overrides/build.gni")
 
-import("//build/toolchain/arm_gcc/arm_toolchain.gni")
+import("${build_root}/toolchain/arm_gcc/arm_toolchain.gni")
 
 declare_args() {
   zephyr_ar = ""
diff --git a/config/nrfconnect/chip-module/CMakeLists.txt b/config/nrfconnect/chip-module/CMakeLists.txt
index 91dfe15..d92e2ca 100644
--- a/config/nrfconnect/chip-module/CMakeLists.txt
+++ b/config/nrfconnect/chip-module/CMakeLists.txt
@@ -67,6 +67,10 @@
 # Helper macros
 # ==============================================================================
 
+macro(chip_gn_arg_import FILE)
+    string(APPEND CHIP_GN_ARGS "import(\"${FILE}\")\n")
+endmacro()
+
 macro(chip_gn_arg_string ARG STRING)
     string(APPEND CHIP_GN_ARGS "${ARG} = \"${STRING}\"\n")
 endmacro()
@@ -96,6 +100,8 @@
     get_filename_component(CHIP_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../.. REALPATH)
 endif()
 
+set(GN_ROOT_TARGET ${CHIP_ROOT}/config/nrfconnect/chip-gn)
+
 # Prepare compiler flags
 
 if (CONFIG_ARM)
@@ -139,7 +145,7 @@
 endif()
 
 if (CONFIG_CHIP_LIB_SHELL)
-    list(APPEND CHIP_LIBRARIES ${CMAKE_CURRENT_BINARY_DIR}/obj/third_party/connectedhomeip/src/lib/shell/lib/libCHIPShell.a)
+    list(APPEND CHIP_LIBRARIES -lCHIPShell)
 endif()
 
 if (CONFIG_CHIP_PW_RPC)
@@ -170,10 +176,39 @@
     zephyr_set_openthread_config(${CHIP_OPENTHREAD_CONFIG})
 endif()
 
+# Find required programs
+
+find_program(GN_EXECUTABLE gn)
+if (${GN_EXECUTABLE} STREQUAL GN_EXECUTABLE-NOTFOUND)
+    message(FATAL_ERROR "The 'gn' command was not found. Make sure you have GN installed.")
+else()
+    # Parse the 'gn --version' output to find the installed version.
+    set(MIN_GN_VERSION 1851)
+    execute_process(
+        COMMAND
+        ${GN_EXECUTABLE} --version
+        OUTPUT_VARIABLE gn_version_output
+        ERROR_VARIABLE  gn_error_output
+        RESULT_VARIABLE gn_status
+    )
+
+    if(${gn_status} EQUAL 0)
+        if(gn_version_output VERSION_LESS ${MIN_GN_VERSION})
+            message(FATAL_ERROR "Found unsuitable version of 'gn'. Required is at least ${MIN_GN_VERSION}")
+        endif()
+    else()
+        message(FATAL_ERROR "Could NOT find working gn: Found gn (${GN_EXECUTABLE}), but failed to load with:\n ${gn_error_output}")
+    endif()
+endif()
+
 # ==============================================================================
 # Generate configuration for CHIP GN build system
 # ==============================================================================
 
+if (CONFIG_CHIP_PW_RPC)
+    chip_gn_arg_import("${GN_ROOT_TARGET}/lib/pw_rpc/pw_rpc.gni")
+endif()
+
 chip_gn_arg_cflags("target_cflags"                          ${CHIP_CFLAGS})
 chip_gn_arg_cflags("target_cflags_c"                        ${CHIP_CFLAGS_C})
 chip_gn_arg_cflags("target_cflags_cc"                       ${CHIP_CFLAGS_CC})
@@ -209,7 +244,7 @@
     PREFIX                  ${CMAKE_CURRENT_BINARY_DIR}
     SOURCE_DIR              ${CHIP_ROOT}
     BINARY_DIR              ${CMAKE_CURRENT_BINARY_DIR}
-    CONFIGURE_COMMAND       gn --root=${CHIP_ROOT}/config/nrfconnect/chip-gn gen --check --fail-on-unused-args ${CMAKE_CURRENT_BINARY_DIR}
+    CONFIGURE_COMMAND       ${GN_EXECUTABLE} --root=${CHIP_ROOT} --root-target=${GN_ROOT_TARGET} --dotfile=${GN_ROOT_TARGET}/.gn gen --check --fail-on-unused-args ${CMAKE_CURRENT_BINARY_DIR}
     BUILD_COMMAND           ninja
     INSTALL_COMMAND         ""
     BUILD_BYPRODUCTS        ${CHIP_LIBRARIES}
diff --git a/config/qpg6100/toolchain/BUILD.gn b/config/qpg6100/toolchain/BUILD.gn
index bbf396b..3860a8e 100644
--- a/config/qpg6100/toolchain/BUILD.gn
+++ b/config/qpg6100/toolchain/BUILD.gn
@@ -12,9 +12,10 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import("//build_overrides/build.gni")
 import("//build_overrides/chip.gni")
 
-import("//build/toolchain/arm_gcc/arm_toolchain.gni")
+import("${build_root}/toolchain/arm_gcc/arm_toolchain.gni")
 
 arm_toolchain("qpg6100_lock_app") {
   toolchain_args = {
diff --git a/config/standalone/toolchain/BUILD.gn b/config/standalone/toolchain/BUILD.gn
index 5c745a8..8e9160f 100644
--- a/config/standalone/toolchain/BUILD.gn
+++ b/config/standalone/toolchain/BUILD.gn
@@ -12,9 +12,10 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import("//build_overrides/build.gni")
 import("//build_overrides/chip.gni")
 
-import("//build/toolchain/gcc_toolchain.gni")
+import("${build_root}/toolchain/gcc_toolchain.gni")
 
 gcc_toolchain("standalone") {
   toolchain_args = {
diff --git a/examples/all-clusters-app/linux/.gn b/examples/all-clusters-app/linux/.gn
index c3cfa5f..5d1ce75 100644
--- a/examples/all-clusters-app/linux/.gn
+++ b/examples/all-clusters-app/linux/.gn
@@ -12,8 +12,10 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import("//build_overrides/build.gni")
+
 # The location of the build configuration file.
-buildconfig = "//build/config/BUILDCONFIG.gn"
+buildconfig = "${build_root}/config/BUILDCONFIG.gn"
 
 # CHIP uses angle bracket includes.
 check_system_includes = true
diff --git a/examples/all-clusters-app/linux/BUILD.gn b/examples/all-clusters-app/linux/BUILD.gn
index 06512ad..a945883 100644
--- a/examples/all-clusters-app/linux/BUILD.gn
+++ b/examples/all-clusters-app/linux/BUILD.gn
@@ -12,9 +12,10 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import("//build_overrides/build.gni")
 import("//build_overrides/chip.gni")
 
-import("${chip_root}/build/chip/tools.gni")
+import("${build_root}/chip/tools.gni")
 
 assert(chip_build_tools)
 
diff --git a/examples/all-clusters-app/linux/build b/examples/all-clusters-app/linux/build
deleted file mode 120000
index d56ed62..0000000
--- a/examples/all-clusters-app/linux/build
+++ /dev/null
@@ -1 +0,0 @@
-third_party/connectedhomeip/build
\ No newline at end of file
diff --git a/examples/bridge-app/linux/.gn b/examples/bridge-app/linux/.gn
index 19b16f1..7072870 100644
--- a/examples/bridge-app/linux/.gn
+++ b/examples/bridge-app/linux/.gn
@@ -12,8 +12,10 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import("//build_overrides/build.gni")
+
 # The location of the build configuration file.
-buildconfig = "//build/config/BUILDCONFIG.gn"
+buildconfig = "${build_root}/config/BUILDCONFIG.gn"
 
 # CHIP uses angle bracket includes.
 check_system_includes = true
diff --git a/build_overrides/esp32.gni b/examples/build_overrides/build.gni
similarity index 77%
copy from build_overrides/esp32.gni
copy to examples/build_overrides/build.gni
index 3a2252c..323b150 100644
--- a/build_overrides/esp32.gni
+++ b/examples/build_overrides/build.gni
@@ -1,4 +1,4 @@
-# Copyright (c) 2020 Project CHIP Authors
+# Copyright (c) 2021 Project CHIP Authors
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -11,3 +11,8 @@
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.
+
+declare_args() {
+  # Root directory for build files.
+  build_root = "//third_party/connectedhomeip/build"
+}
diff --git a/examples/chip-tool/.gn b/examples/chip-tool/.gn
index c3cfa5f..5d1ce75 100644
--- a/examples/chip-tool/.gn
+++ b/examples/chip-tool/.gn
@@ -12,8 +12,10 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import("//build_overrides/build.gni")
+
 # The location of the build configuration file.
-buildconfig = "//build/config/BUILDCONFIG.gn"
+buildconfig = "${build_root}/config/BUILDCONFIG.gn"
 
 # CHIP uses angle bracket includes.
 check_system_includes = true
diff --git a/examples/chip-tool/BUILD.gn b/examples/chip-tool/BUILD.gn
index 9ae80a2..8b9acee 100644
--- a/examples/chip-tool/BUILD.gn
+++ b/examples/chip-tool/BUILD.gn
@@ -12,9 +12,10 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import("//build_overrides/build.gni")
 import("//build_overrides/chip.gni")
 
-import("${chip_root}/build/chip/tools.gni")
+import("${build_root}/chip/tools.gni")
 
 assert(chip_build_tools)
 
diff --git a/examples/chip-tool/build b/examples/chip-tool/build
deleted file mode 120000
index d56ed62..0000000
--- a/examples/chip-tool/build
+++ /dev/null
@@ -1 +0,0 @@
-third_party/connectedhomeip/build
\ No newline at end of file
diff --git a/examples/lighting-app/efr32/.gn b/examples/lighting-app/efr32/.gn
index 89dc9a6..3d48789 100644
--- a/examples/lighting-app/efr32/.gn
+++ b/examples/lighting-app/efr32/.gn
@@ -12,8 +12,10 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import("//build_overrides/build.gni")
+
 # The location of the build configuration file.
-buildconfig = "//build/config/BUILDCONFIG.gn"
+buildconfig = "${build_root}/config/BUILDCONFIG.gn"
 
 # CHIP uses angle bracket includes.
 check_system_includes = true
diff --git a/examples/lighting-app/efr32/BUILD.gn b/examples/lighting-app/efr32/BUILD.gn
index 0793614..b2c5ab0 100644
--- a/examples/lighting-app/efr32/BUILD.gn
+++ b/examples/lighting-app/efr32/BUILD.gn
@@ -12,9 +12,11 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-import("//build/config/defaults.gni")
+import("//build_overrides/build.gni")
 import("//build_overrides/chip.gni")
 import("//build_overrides/efr32_sdk.gni")
+
+import("${build_root}/config/defaults.gni")
 import("${efr32_sdk_build_root}/efr32_executable.gni")
 import("${efr32_sdk_build_root}/efr32_sdk.gni")
 
diff --git a/examples/lighting-app/efr32/build b/examples/lighting-app/efr32/build
deleted file mode 120000
index d56ed62..0000000
--- a/examples/lighting-app/efr32/build
+++ /dev/null
@@ -1 +0,0 @@
-third_party/connectedhomeip/build
\ No newline at end of file
diff --git a/examples/lighting-app/linux/.gn b/examples/lighting-app/linux/.gn
index c3cfa5f..5d1ce75 100644
--- a/examples/lighting-app/linux/.gn
+++ b/examples/lighting-app/linux/.gn
@@ -12,8 +12,10 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import("//build_overrides/build.gni")
+
 # The location of the build configuration file.
-buildconfig = "//build/config/BUILDCONFIG.gn"
+buildconfig = "${build_root}/config/BUILDCONFIG.gn"
 
 # CHIP uses angle bracket includes.
 check_system_includes = true
diff --git a/examples/lighting-app/linux/BUILD.gn b/examples/lighting-app/linux/BUILD.gn
index 80477ba..b3cee92 100644
--- a/examples/lighting-app/linux/BUILD.gn
+++ b/examples/lighting-app/linux/BUILD.gn
@@ -12,9 +12,10 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import("//build_overrides/build.gni")
 import("//build_overrides/chip.gni")
 
-import("${chip_root}/build/chip/tools.gni")
+import("${build_root}/chip/tools.gni")
 
 assert(chip_build_tools)
 
diff --git a/examples/lighting-app/linux/build b/examples/lighting-app/linux/build
deleted file mode 120000
index d56ed62..0000000
--- a/examples/lighting-app/linux/build
+++ /dev/null
@@ -1 +0,0 @@
-third_party/connectedhomeip/build
\ No newline at end of file
diff --git a/examples/lock-app/cc13x2_26x2/.gn b/examples/lock-app/cc13x2_26x2/.gn
index 89dc9a6..3d48789 100644
--- a/examples/lock-app/cc13x2_26x2/.gn
+++ b/examples/lock-app/cc13x2_26x2/.gn
@@ -12,8 +12,10 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import("//build_overrides/build.gni")
+
 # The location of the build configuration file.
-buildconfig = "//build/config/BUILDCONFIG.gn"
+buildconfig = "${build_root}/config/BUILDCONFIG.gn"
 
 # CHIP uses angle bracket includes.
 check_system_includes = true
diff --git a/examples/lock-app/cc13x2_26x2/BUILD.gn b/examples/lock-app/cc13x2_26x2/BUILD.gn
index f74f6ec..1a76acf 100644
--- a/examples/lock-app/cc13x2_26x2/BUILD.gn
+++ b/examples/lock-app/cc13x2_26x2/BUILD.gn
@@ -12,10 +12,13 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-import("//build/config/defaults.gni")
+import("//build_overrides/build.gni")
 import("//build_overrides/chip.gni")
 import("//build_overrides/openthread.gni")
 import("//build_overrides/ti_simplelink_sdk.gni")
+
+import("${build_root}/config/defaults.gni")
+
 import("${ti_simplelink_sdk_build_root}/ti_simplelink_executable.gni")
 import("${ti_simplelink_sdk_build_root}/ti_simplelink_sdk.gni")
 
diff --git a/examples/lock-app/cc13x2_26x2/build b/examples/lock-app/cc13x2_26x2/build
deleted file mode 120000
index d56ed62..0000000
--- a/examples/lock-app/cc13x2_26x2/build
+++ /dev/null
@@ -1 +0,0 @@
-third_party/connectedhomeip/build
\ No newline at end of file
diff --git a/examples/lock-app/efr32/.gn b/examples/lock-app/efr32/.gn
index 89dc9a6..3d48789 100644
--- a/examples/lock-app/efr32/.gn
+++ b/examples/lock-app/efr32/.gn
@@ -12,8 +12,10 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import("//build_overrides/build.gni")
+
 # The location of the build configuration file.
-buildconfig = "//build/config/BUILDCONFIG.gn"
+buildconfig = "${build_root}/config/BUILDCONFIG.gn"
 
 # CHIP uses angle bracket includes.
 check_system_includes = true
diff --git a/examples/lock-app/efr32/BUILD.gn b/examples/lock-app/efr32/BUILD.gn
index 2670214..765ec15 100644
--- a/examples/lock-app/efr32/BUILD.gn
+++ b/examples/lock-app/efr32/BUILD.gn
@@ -12,9 +12,11 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-import("//build/config/defaults.gni")
+import("//build_overrides/build.gni")
 import("//build_overrides/chip.gni")
 import("//build_overrides/efr32_sdk.gni")
+
+import("${build_root}/config/defaults.gni")
 import("${efr32_sdk_build_root}/efr32_executable.gni")
 import("${efr32_sdk_build_root}/efr32_sdk.gni")
 
diff --git a/examples/lock-app/efr32/build b/examples/lock-app/efr32/build
deleted file mode 120000
index d56ed62..0000000
--- a/examples/lock-app/efr32/build
+++ /dev/null
@@ -1 +0,0 @@
-third_party/connectedhomeip/build
\ No newline at end of file
diff --git a/examples/lock-app/k32w/.gn b/examples/lock-app/k32w/.gn
index 9453291..3d48789 100644
--- a/examples/lock-app/k32w/.gn
+++ b/examples/lock-app/k32w/.gn
@@ -12,15 +12,14 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import("//build_overrides/build.gni")
+
 # The location of the build configuration file.
-buildconfig = "//build/config/BUILDCONFIG.gn"
+buildconfig = "${build_root}/config/BUILDCONFIG.gn"
 
 # CHIP uses angle bracket includes.
 check_system_includes = true
 
-# Allow loading paths relative to //gn.
-secondary_source = "//third_party/connectedhomeip/gn/"
-
 default_args = {
   target_cpu = "arm"
   target_os = "freertos"
diff --git a/examples/lock-app/k32w/build b/examples/lock-app/k32w/build
deleted file mode 120000
index d56ed62..0000000
--- a/examples/lock-app/k32w/build
+++ /dev/null
@@ -1 +0,0 @@
-third_party/connectedhomeip/build
\ No newline at end of file
diff --git a/examples/lock-app/qpg6100/.gn b/examples/lock-app/qpg6100/.gn
index 89dc9a6..3d48789 100644
--- a/examples/lock-app/qpg6100/.gn
+++ b/examples/lock-app/qpg6100/.gn
@@ -12,8 +12,10 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import("//build_overrides/build.gni")
+
 # The location of the build configuration file.
-buildconfig = "//build/config/BUILDCONFIG.gn"
+buildconfig = "${build_root}/config/BUILDCONFIG.gn"
 
 # CHIP uses angle bracket includes.
 check_system_includes = true
diff --git a/examples/lock-app/qpg6100/BUILD.gn b/examples/lock-app/qpg6100/BUILD.gn
index f457bf0..228f1f3 100644
--- a/examples/lock-app/qpg6100/BUILD.gn
+++ b/examples/lock-app/qpg6100/BUILD.gn
@@ -12,9 +12,11 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-import("//build/config/defaults.gni")
+import("//build_overrides/build.gni")
 import("//build_overrides/chip.gni")
 import("//build_overrides/qpg6100_sdk.gni")
+
+import("${build_root}/config/defaults.gni")
 import("${qpg6100_sdk_build_root}/qpg6100_executable.gni")
 import("${qpg6100_sdk_build_root}/qpg6100_sdk.gni")
 
diff --git a/examples/lock-app/qpg6100/build b/examples/lock-app/qpg6100/build
deleted file mode 120000
index d56ed62..0000000
--- a/examples/lock-app/qpg6100/build
+++ /dev/null
@@ -1 +0,0 @@
-third_party/connectedhomeip/build
\ No newline at end of file
diff --git a/examples/minimal-mdns/.gn b/examples/minimal-mdns/.gn
index c3cfa5f..5d1ce75 100644
--- a/examples/minimal-mdns/.gn
+++ b/examples/minimal-mdns/.gn
@@ -12,8 +12,10 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import("//build_overrides/build.gni")
+
 # The location of the build configuration file.
-buildconfig = "//build/config/BUILDCONFIG.gn"
+buildconfig = "${build_root}/config/BUILDCONFIG.gn"
 
 # CHIP uses angle bracket includes.
 check_system_includes = true
diff --git a/examples/minimal-mdns/BUILD.gn b/examples/minimal-mdns/BUILD.gn
index 06d530c..f1c5d2d 100644
--- a/examples/minimal-mdns/BUILD.gn
+++ b/examples/minimal-mdns/BUILD.gn
@@ -12,9 +12,10 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import("//build_overrides/build.gni")
 import("//build_overrides/chip.gni")
 
-import("${chip_root}/build/chip/tools.gni")
+import("${build_root}/chip/tools.gni")
 
 static_library("minimal-mdns-example-common") {
   sources = [
diff --git a/examples/minimal-mdns/build b/examples/minimal-mdns/build
deleted file mode 120000
index d56ed62..0000000
--- a/examples/minimal-mdns/build
+++ /dev/null
@@ -1 +0,0 @@
-third_party/connectedhomeip/build
\ No newline at end of file
diff --git a/examples/persistent-storage/efr32/.gn b/examples/persistent-storage/efr32/.gn
index b091040..81cec9d 100644
--- a/examples/persistent-storage/efr32/.gn
+++ b/examples/persistent-storage/efr32/.gn
@@ -12,8 +12,10 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import("//build_overrides/build.gni")
+
 # The location of the build configuration file.
-buildconfig = "//build/config/BUILDCONFIG.gn"
+buildconfig = "${build_root}/config/BUILDCONFIG.gn"
 
 # CHIP uses angle bracket includes.
 check_system_includes = true
diff --git a/examples/persistent-storage/efr32/BUILD.gn b/examples/persistent-storage/efr32/BUILD.gn
index fc3bc60..670588f 100644
--- a/examples/persistent-storage/efr32/BUILD.gn
+++ b/examples/persistent-storage/efr32/BUILD.gn
@@ -12,10 +12,13 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-import("//build/config/defaults.gni")
+import("//build_overrides/build.gni")
 import("//build_overrides/chip.gni")
 import("//build_overrides/efr32_sdk.gni")
 import("//build_overrides/pigweed.gni")
+
+import("${build_root}/config/defaults.gni")
+
 import("${efr32_sdk_build_root}/efr32_executable.gni")
 import("${efr32_sdk_build_root}/efr32_sdk.gni")
 
diff --git a/examples/persistent-storage/efr32/build b/examples/persistent-storage/efr32/build
deleted file mode 120000
index d56ed62..0000000
--- a/examples/persistent-storage/efr32/build
+++ /dev/null
@@ -1 +0,0 @@
-third_party/connectedhomeip/build
\ No newline at end of file
diff --git a/examples/shell/qpg6100/.gn b/examples/shell/qpg6100/.gn
index 89dc9a6..3d48789 100644
--- a/examples/shell/qpg6100/.gn
+++ b/examples/shell/qpg6100/.gn
@@ -12,8 +12,10 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import("//build_overrides/build.gni")
+
 # The location of the build configuration file.
-buildconfig = "//build/config/BUILDCONFIG.gn"
+buildconfig = "${build_root}/config/BUILDCONFIG.gn"
 
 # CHIP uses angle bracket includes.
 check_system_includes = true
diff --git a/examples/shell/qpg6100/BUILD.gn b/examples/shell/qpg6100/BUILD.gn
index c634817..f587807 100644
--- a/examples/shell/qpg6100/BUILD.gn
+++ b/examples/shell/qpg6100/BUILD.gn
@@ -12,9 +12,11 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-import("//build/config/defaults.gni")
+import("//build_overrides/build.gni")
 import("//build_overrides/chip.gni")
 import("//build_overrides/qpg6100_sdk.gni")
+
+import("${build_root}/config/defaults.gni")
 import("${qpg6100_sdk_build_root}/qpg6100_executable.gni")
 import("${qpg6100_sdk_build_root}/qpg6100_sdk.gni")
 
diff --git a/examples/shell/qpg6100/build b/examples/shell/qpg6100/build
deleted file mode 120000
index d56ed62..0000000
--- a/examples/shell/qpg6100/build
+++ /dev/null
@@ -1 +0,0 @@
-third_party/connectedhomeip/build
\ No newline at end of file
diff --git a/examples/shell/standalone/.gn b/examples/shell/standalone/.gn
index c3cfa5f..5d1ce75 100644
--- a/examples/shell/standalone/.gn
+++ b/examples/shell/standalone/.gn
@@ -12,8 +12,10 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import("//build_overrides/build.gni")
+
 # The location of the build configuration file.
-buildconfig = "//build/config/BUILDCONFIG.gn"
+buildconfig = "${build_root}/config/BUILDCONFIG.gn"
 
 # CHIP uses angle bracket includes.
 check_system_includes = true
diff --git a/examples/shell/standalone/BUILD.gn b/examples/shell/standalone/BUILD.gn
index 0db81e8..9ac1796 100644
--- a/examples/shell/standalone/BUILD.gn
+++ b/examples/shell/standalone/BUILD.gn
@@ -12,10 +12,11 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import("//build_overrides/build.gni")
 import("//build_overrides/chip.gni")
 import("//build_overrides/openthread.gni")
 
-import("${chip_root}/build/chip/tools.gni")
+import("${build_root}/chip/tools.gni")
 
 assert(chip_build_tools)
 
diff --git a/examples/shell/standalone/build b/examples/shell/standalone/build
deleted file mode 120000
index d56ed62..0000000
--- a/examples/shell/standalone/build
+++ /dev/null
@@ -1 +0,0 @@
-third_party/connectedhomeip/build
\ No newline at end of file
diff --git a/scripts/pigweed.json b/scripts/pigweed.json
index e281e0e..eeb80b3 100644
--- a/scripts/pigweed.json
+++ b/scripts/pigweed.json
@@ -1,7 +1,7 @@
 [
     {
         "path": "gn/gn/${os}-${arch=amd64,arm64}",
-        "tags": ["git_revision:132588e1f9c2bf07b0cc0516e190b445de1153a7"]
+        "tags": ["git_revision:d62642c920e6a0d1756316d225a90fd6faa9e21e"]
     },
     {
         "path": "infra/ninja/${os}-${arch=amd64}",
diff --git a/src/BUILD.gn b/src/BUILD.gn
index 6d91bce..9d78b3f 100644
--- a/src/BUILD.gn
+++ b/src/BUILD.gn
@@ -12,9 +12,10 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import("//build_overrides/build.gni")
 import("//build_overrides/chip.gni")
 
-import("${chip_root}/build/chip/tests.gni")
+import("${build_root}/chip/tests.gni")
 import("${chip_root}/src/ble/ble.gni")
 import("${chip_root}/src/lwip/lwip.gni")
 import("${chip_root}/src/platform/device.gni")
@@ -34,7 +35,7 @@
 }
 
 if (chip_build_tests) {
-  import("${chip_root}/build/chip/chip_test_group.gni")
+  import("${build_root}/chip/chip_test_group.gni")
 
   chip_test_group("tests") {
     deps = [
diff --git a/src/app/tests/BUILD.gn b/src/app/tests/BUILD.gn
index 9ce8498..6c61d48 100644
--- a/src/app/tests/BUILD.gn
+++ b/src/app/tests/BUILD.gn
@@ -12,10 +12,11 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import("//build_overrides/build.gni")
 import("//build_overrides/chip.gni")
 import("//build_overrides/nlunit_test.gni")
 
-import("${chip_root}/build/chip/chip_test_suite.gni")
+import("${build_root}/chip/chip_test_suite.gni")
 
 chip_test_suite("tests") {
   output_name = "libAppTests"
diff --git a/src/app/tests/integration/BUILD.gn b/src/app/tests/integration/BUILD.gn
index 2793332..23241b6 100644
--- a/src/app/tests/integration/BUILD.gn
+++ b/src/app/tests/integration/BUILD.gn
@@ -12,9 +12,10 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import("//build_overrides/build.gni")
 import("//build_overrides/chip.gni")
 
-import("${chip_root}/build/chip/tools.gni")
+import("${build_root}/chip/tools.gni")
 
 assert(chip_build_tools)
 
diff --git a/src/ble/BUILD.gn b/src/ble/BUILD.gn
index 6754f23..a75b94c 100644
--- a/src/ble/BUILD.gn
+++ b/src/ble/BUILD.gn
@@ -12,10 +12,11 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import("//build_overrides/build.gni")
 import("//build_overrides/chip.gni")
 
-import("${chip_root}/build/chip/buildconfig_header.gni")
-import("${chip_root}/build/chip/tests.gni")
+import("${build_root}/chip/buildconfig_header.gni")
+import("${build_root}/chip/tests.gni")
 import("${chip_root}/src/platform/device.gni")
 import("ble.gni")
 
diff --git a/src/ble/tests/BUILD.gn b/src/ble/tests/BUILD.gn
index 49a3acc..6163ec8 100644
--- a/src/ble/tests/BUILD.gn
+++ b/src/ble/tests/BUILD.gn
@@ -12,10 +12,11 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import("//build_overrides/build.gni")
 import("//build_overrides/chip.gni")
 import("//build_overrides/nlunit_test.gni")
 
-import("${chip_root}/build/chip/chip_test_suite.gni")
+import("${build_root}/chip/chip_test_suite.gni")
 
 chip_test_suite("tests") {
   output_name = "libBleLayerTests"
diff --git a/src/controller/java/BUILD.gn b/src/controller/java/BUILD.gn
index 0882fd6..ee23c1e 100644
--- a/src/controller/java/BUILD.gn
+++ b/src/controller/java/BUILD.gn
@@ -12,10 +12,11 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import("//build_overrides/build.gni")
 import("//build_overrides/chip.gni")
 
-import("//build/config/android_abi.gni")
-import("${chip_root}/build/chip/java/rules.gni")
+import("${build_root}/chip/java/rules.gni")
+import("${build_root}/config/android_abi.gni")
 
 shared_library("jni") {
   output_name = "libCHIPController"
@@ -42,7 +43,7 @@
 
   data_deps = [
     ":jni",
-    "//build/chip/java:shared_cpplib",
+    "${build_root}/chip/java:shared_cpplib",
   ]
 
   sources = [
diff --git a/src/controller/python/BUILD.gn b/src/controller/python/BUILD.gn
index 992a1be..fa98bb9 100644
--- a/src/controller/python/BUILD.gn
+++ b/src/controller/python/BUILD.gn
@@ -12,11 +12,13 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import("//build_overrides/build.gni")
 import("//build_overrides/chip.gni")
 import("//build_overrides/pigweed.gni")
+
 import("$dir_pw_build/python.gni")
 
-import("${chip_root}/build/chip/tools.gni")
+import("${build_root}/chip/tools.gni")
 import("${dir_pw_unit_test}/test.gni")
 
 config("controller_wno_deprecate") {
@@ -123,10 +125,8 @@
 
   public_deps = [ ":ChipDeviceCtrl" ]
 
-  pythontags = exec_script("${chip_root}/build/chip/python_gen_tags.py",
-                           [],
-                           "list lines",
-                           [])
+  pythontags =
+      exec_script("${build_root}/chip/python_gen_tags.py", [], "list lines", [])
   pythontagsStr = string_join("", pythontags)
   output_name = "chip-0.0-$pythontagsStr.whl"
   outputs = [ "${_dist_dir}/$output_name" ]
diff --git a/src/credentials/tests/BUILD.gn b/src/credentials/tests/BUILD.gn
index 35306cb..83a32d7 100644
--- a/src/credentials/tests/BUILD.gn
+++ b/src/credentials/tests/BUILD.gn
@@ -12,10 +12,11 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import("//build_overrides/build.gni")
 import("//build_overrides/chip.gni")
 import("//build_overrides/nlunit_test.gni")
 
-import("${chip_root}/build/chip/chip_test_suite.gni")
+import("${build_root}/chip/chip_test_suite.gni")
 
 chip_test_suite("tests") {
   output_name = "libChipCredentials"
diff --git a/src/crypto/BUILD.gn b/src/crypto/BUILD.gn
index d04538e..dd2528a 100644
--- a/src/crypto/BUILD.gn
+++ b/src/crypto/BUILD.gn
@@ -12,10 +12,11 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import("//build_overrides/build.gni")
 import("//build_overrides/chip.gni")
 import("//build_overrides/nlassert.gni")
 
-import("${chip_root}/build/chip/buildconfig_header.gni")
+import("${build_root}/chip/buildconfig_header.gni")
 
 import("crypto.gni")
 
@@ -34,7 +35,7 @@
 }
 
 if (chip_crypto == "openssl") {
-  import("//build/config/linux/pkg_config.gni")
+  import("${build_root}/config/linux/pkg_config.gni")
 
   pkg_config("openssl_config") {
     packages = [ "openssl" ]
@@ -60,9 +61,15 @@
   ]
 
   public_configs = []
+
   if (chip_crypto == "mbedtls") {
     sources += [ "CHIPCryptoPALmbedTLS.cpp" ]
-    public_deps += [ "${mbedtls_root}:mbedtls" ]
+
+    external_mbedtls = current_os == "zephyr"
+
+    if (!external_mbedtls) {
+      public_deps += [ "${mbedtls_root}:mbedtls" ]
+    }
   } else if (chip_crypto == "openssl") {
     sources += [ "CHIPCryptoPALOpenSSL.cpp" ]
     public_configs += [ ":openssl_config" ]
diff --git a/src/crypto/tests/BUILD.gn b/src/crypto/tests/BUILD.gn
index 3ce968d..c4f3fe5 100644
--- a/src/crypto/tests/BUILD.gn
+++ b/src/crypto/tests/BUILD.gn
@@ -12,10 +12,11 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import("//build_overrides/build.gni")
 import("//build_overrides/chip.gni")
 import("//build_overrides/nlunit_test.gni")
 
-import("${chip_root}/build/chip/chip_test_suite.gni")
+import("${build_root}/chip/chip_test_suite.gni")
 
 chip_test_suite("tests") {
   output_name = "libChipCryptoTests"
diff --git a/src/inet/BUILD.gn b/src/inet/BUILD.gn
index 93576e7..1076c00 100644
--- a/src/inet/BUILD.gn
+++ b/src/inet/BUILD.gn
@@ -12,13 +12,14 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import("//build_overrides/build.gni")
 import("//build_overrides/chip.gni")
 import("//build_overrides/nlassert.gni")
 import("//build_overrides/nlfaultinjection.gni")
 import("//build_overrides/nlio.gni")
 
-import("${chip_root}/build/chip/buildconfig_header.gni")
-import("${chip_root}/build/chip/tests.gni")
+import("${build_root}/chip/buildconfig_header.gni")
+import("${build_root}/chip/tests.gni")
 import("${chip_root}/src/lwip/lwip.gni")
 import("${chip_root}/src/platform/device.gni")
 import("inet.gni")
diff --git a/src/inet/tests/BUILD.gn b/src/inet/tests/BUILD.gn
index 7284161..5d3309a 100644
--- a/src/inet/tests/BUILD.gn
+++ b/src/inet/tests/BUILD.gn
@@ -12,11 +12,12 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import("//build_overrides/build.gni")
 import("//build_overrides/chip.gni")
 import("//build_overrides/nlunit_test.gni")
 
-import("${chip_root}/build/chip/chip_test_suite.gni")
-import("${chip_root}/build/chip/tests.gni")
+import("${build_root}/chip/chip_test_suite.gni")
+import("${build_root}/chip/tests.gni")
 import("${chip_root}/src/lwip/lwip.gni")
 import("${chip_root}/src/platform/device.gni")
 
diff --git a/src/lib/asn1/tests/BUILD.gn b/src/lib/asn1/tests/BUILD.gn
index 52a49a9..6d36781 100644
--- a/src/lib/asn1/tests/BUILD.gn
+++ b/src/lib/asn1/tests/BUILD.gn
@@ -12,10 +12,11 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import("//build_overrides/build.gni")
 import("//build_overrides/chip.gni")
 import("//build_overrides/nlunit_test.gni")
 
-import("${chip_root}/build/chip/chip_test_suite.gni")
+import("${build_root}/chip/chip_test_suite.gni")
 
 chip_test_suite("tests") {
   output_name = "libASN1Tests"
diff --git a/src/lib/core/BUILD.gn b/src/lib/core/BUILD.gn
index 91e80c9..faa8629 100644
--- a/src/lib/core/BUILD.gn
+++ b/src/lib/core/BUILD.gn
@@ -12,11 +12,12 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import("//build_overrides/build.gni")
 import("//build_overrides/chip.gni")
 import("//build_overrides/nlio.gni")
 
-import("${chip_root}/build/chip/buildconfig_header.gni")
-import("${chip_root}/build/chip/tests.gni")
+import("${build_root}/chip/buildconfig_header.gni")
+import("${build_root}/chip/tests.gni")
 import("${chip_root}/src/inet/inet.gni")
 import("core.gni")
 
diff --git a/src/lib/core/tests/BUILD.gn b/src/lib/core/tests/BUILD.gn
index 92b13a2..469bbaf 100644
--- a/src/lib/core/tests/BUILD.gn
+++ b/src/lib/core/tests/BUILD.gn
@@ -12,10 +12,11 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import("//build_overrides/build.gni")
 import("//build_overrides/chip.gni")
 import("//build_overrides/nlunit_test.gni")
 
-import("${chip_root}/build/chip/chip_test_suite.gni")
+import("${build_root}/chip/chip_test_suite.gni")
 
 chip_test_suite("tests") {
   output_name = "libCoreTests"
diff --git a/src/lib/mdns/minimal/core/tests/BUILD.gn b/src/lib/mdns/minimal/core/tests/BUILD.gn
index e1ea787..6e0909c 100644
--- a/src/lib/mdns/minimal/core/tests/BUILD.gn
+++ b/src/lib/mdns/minimal/core/tests/BUILD.gn
@@ -12,10 +12,11 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import("//build_overrides/build.gni")
 import("//build_overrides/chip.gni")
 import("//build_overrides/nlunit_test.gni")
 
-import("${chip_root}/build/chip/chip_test_suite.gni")
+import("${build_root}/chip/chip_test_suite.gni")
 
 chip_test_suite("tests") {
   output_name = "libMinimalMdnsCoreTests"
diff --git a/src/lib/mdns/minimal/records/tests/BUILD.gn b/src/lib/mdns/minimal/records/tests/BUILD.gn
index 4f91149..280e2df 100644
--- a/src/lib/mdns/minimal/records/tests/BUILD.gn
+++ b/src/lib/mdns/minimal/records/tests/BUILD.gn
@@ -12,10 +12,11 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import("//build_overrides/build.gni")
 import("//build_overrides/chip.gni")
 import("//build_overrides/nlunit_test.gni")
 
-import("${chip_root}/build/chip/chip_test_suite.gni")
+import("${build_root}/chip/chip_test_suite.gni")
 
 chip_test_suite("tests") {
   output_name = "LibMinimalMdnsRecordsTests"
diff --git a/src/lib/mdns/minimal/responders/tests/BUILD.gn b/src/lib/mdns/minimal/responders/tests/BUILD.gn
index 407579e..b054329 100644
--- a/src/lib/mdns/minimal/responders/tests/BUILD.gn
+++ b/src/lib/mdns/minimal/responders/tests/BUILD.gn
@@ -12,10 +12,11 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import("//build_overrides/build.gni")
 import("//build_overrides/chip.gni")
 import("//build_overrides/nlunit_test.gni")
 
-import("${chip_root}/build/chip/chip_test_suite.gni")
+import("${build_root}/chip/chip_test_suite.gni")
 
 chip_test_suite("tests") {
   output_name = "LibMinimalMdnsRespondersTests"
diff --git a/src/lib/mdns/minimal/tests/BUILD.gn b/src/lib/mdns/minimal/tests/BUILD.gn
index 44e0c01..c13a09b 100644
--- a/src/lib/mdns/minimal/tests/BUILD.gn
+++ b/src/lib/mdns/minimal/tests/BUILD.gn
@@ -12,10 +12,11 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import("//build_overrides/build.gni")
 import("//build_overrides/chip.gni")
 import("//build_overrides/nlunit_test.gni")
 
-import("${chip_root}/build/chip/chip_test_suite.gni")
+import("${build_root}/chip/chip_test_suite.gni")
 
 chip_test_suite("tests") {
   output_name = "libMinimalMdnstests"
diff --git a/src/lib/shell/BUILD.gn b/src/lib/shell/BUILD.gn
index 1d564d7..956f59c 100644
--- a/src/lib/shell/BUILD.gn
+++ b/src/lib/shell/BUILD.gn
@@ -18,6 +18,7 @@
 
 static_library("shell") {
   output_name = "libCHIPShell"
+  output_dir = "${root_out_dir}/lib"
 
   sources = [
     "commands.cpp",
diff --git a/src/lib/shell/tests/BUILD.gn b/src/lib/shell/tests/BUILD.gn
index 502a3fd..ff1d2d0 100644
--- a/src/lib/shell/tests/BUILD.gn
+++ b/src/lib/shell/tests/BUILD.gn
@@ -12,10 +12,11 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import("//build_overrides/build.gni")
 import("//build_overrides/chip.gni")
 import("//build_overrides/nlunit_test.gni")
 
-import("${chip_root}/build/chip/chip_test_suite.gni")
+import("${build_root}/chip/chip_test_suite.gni")
 
 chip_test_suite("tests") {
   output_name = "libTestShell"
diff --git a/src/lib/support/BUILD.gn b/src/lib/support/BUILD.gn
index af05d53..0ede660 100644
--- a/src/lib/support/BUILD.gn
+++ b/src/lib/support/BUILD.gn
@@ -12,13 +12,14 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import("//build_overrides/build.gni")
 import("//build_overrides/chip.gni")
 import("//build_overrides/nlassert.gni")
 import("//build_overrides/nlfaultinjection.gni")
 import("//build_overrides/nlio.gni")
 
-import("${chip_root}/build/chip/chip_version.gni")
-import("${chip_root}/build/chip/tests.gni")
+import("${build_root}/chip/chip_version.gni")
+import("${build_root}/chip/tests.gni")
 import("${chip_root}/src/lib/core/core.gni")
 
 action("gen_chip_version") {
diff --git a/src/lib/support/tests/BUILD.gn b/src/lib/support/tests/BUILD.gn
index 3f31e46..22c3ea7 100644
--- a/src/lib/support/tests/BUILD.gn
+++ b/src/lib/support/tests/BUILD.gn
@@ -12,10 +12,11 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import("//build_overrides/build.gni")
 import("//build_overrides/chip.gni")
 import("//build_overrides/nlunit_test.gni")
 
-import("${chip_root}/build/chip/chip_test_suite.gni")
+import("${build_root}/chip/chip_test_suite.gni")
 
 chip_test_suite("tests") {
   output_name = "libSupportTests"
diff --git a/src/lwip/BUILD.gn b/src/lwip/BUILD.gn
index 13b97c1..94aedd2 100644
--- a/src/lwip/BUILD.gn
+++ b/src/lwip/BUILD.gn
@@ -12,10 +12,11 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import("//build_overrides/build.gni")
 import("//build_overrides/chip.gni")
 import("//build_overrides/lwip.gni")
 
-import("${chip_root}/build/chip/buildconfig_header.gni")
+import("${build_root}/chip/buildconfig_header.gni")
 import("${chip_root}/src/lwip/lwip.gni")
 import("${lwip_root}/lwip.gni")
 
diff --git a/src/lwip/tests/BUILD.gn b/src/lwip/tests/BUILD.gn
index 3a5db9d..b193022 100644
--- a/src/lwip/tests/BUILD.gn
+++ b/src/lwip/tests/BUILD.gn
@@ -12,10 +12,11 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import("//build_overrides/build.gni")
 import("//build_overrides/chip.gni")
 
-import("${chip_root}/build/chip/chip_test.gni")
-import("${chip_root}/build/chip/chip_test_group.gni")
+import("${build_root}/chip/chip_test.gni")
+import("${build_root}/chip/chip_test_group.gni")
 import("${chip_root}/src/lwip/lwip.gni")
 
 assert(chip_with_lwip)
diff --git a/src/messaging/tests/BUILD.gn b/src/messaging/tests/BUILD.gn
index 0b532a5..5e72204 100644
--- a/src/messaging/tests/BUILD.gn
+++ b/src/messaging/tests/BUILD.gn
@@ -12,11 +12,12 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import("//build_overrides/build.gni")
 import("//build_overrides/chip.gni")
 import("//build_overrides/nlio.gni")
 import("//build_overrides/nlunit_test.gni")
 
-import("${chip_root}/build/chip/chip_test_suite.gni")
+import("${build_root}/chip/chip_test_suite.gni")
 
 chip_test_suite("tests") {
   output_name = "libMessagingLayerTests"
diff --git a/src/messaging/tests/echo/BUILD.gn b/src/messaging/tests/echo/BUILD.gn
index 4b009bd..2bcc4a9 100644
--- a/src/messaging/tests/echo/BUILD.gn
+++ b/src/messaging/tests/echo/BUILD.gn
@@ -12,9 +12,10 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import("//build_overrides/build.gni")
 import("//build_overrides/chip.gni")
 
-import("${chip_root}/build/chip/tools.gni")
+import("${build_root}/chip/tools.gni")
 
 assert(chip_build_tools)
 
diff --git a/src/platform/BUILD.gn b/src/platform/BUILD.gn
index abffbe0..6a616fe 100644
--- a/src/platform/BUILD.gn
+++ b/src/platform/BUILD.gn
@@ -12,17 +12,22 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-import("//build/config/linux/pkg_config.gni")
+import("//build_overrides/build.gni")
 import("//build_overrides/chip.gni")
 import("//build_overrides/nlio.gni")
 import("//build_overrides/pigweed.gni")
-import("${chip_root}/build/chip/buildconfig_header.gni")
+
+import("${build_root}/chip/buildconfig_header.gni")
+import("${build_root}/config/linux/pkg_config.gni")
 
 import("device.gni")
 
 if (chip_enable_openthread) {
   import("//build_overrides/openthread.gni")
-  import("//build_overrides/ot_br_posix.gni")
+
+  if (chip_device_platform == "linux" || chip_device_platform == "Darwin") {
+    import("//build_overrides/ot_br_posix.gni")
+  }
 }
 
 if (chip_device_platform == "linux" && chip_enable_mdns) {
diff --git a/src/platform/Linux/dbus/bluez/BUILD.gn b/src/platform/Linux/dbus/bluez/BUILD.gn
index 308fecc..6b569e6 100644
--- a/src/platform/Linux/dbus/bluez/BUILD.gn
+++ b/src/platform/Linux/dbus/bluez/BUILD.gn
@@ -12,9 +12,9 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-import("//build_overrides/chip.gni")
+import("//build_overrides/build.gni")
 
-import("${chip_root}/build/chip/linux/gdbus_library.gni")
+import("${build_root}/chip/linux/gdbus_library.gni")
 
 gdbus_library("bluez") {
   sources = [ "DbusBluez.xml" ]
diff --git a/src/platform/Linux/dbus/wpa/BUILD.gn b/src/platform/Linux/dbus/wpa/BUILD.gn
index 9fdd7e5..fc71561 100644
--- a/src/platform/Linux/dbus/wpa/BUILD.gn
+++ b/src/platform/Linux/dbus/wpa/BUILD.gn
@@ -12,9 +12,9 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-import("//build_overrides/chip.gni")
+import("//build_overrides/build.gni")
 
-import("${chip_root}/build/chip/linux/gdbus_library.gni")
+import("${build_root}/chip/linux/gdbus_library.gni")
 
 gdbus_library("wpa") {
   sources = [
diff --git a/src/platform/tests/BUILD.gn b/src/platform/tests/BUILD.gn
index ac3f86d..1f9756e 100644
--- a/src/platform/tests/BUILD.gn
+++ b/src/platform/tests/BUILD.gn
@@ -12,13 +12,14 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import("//build_overrides/build.gni")
 import("//build_overrides/chip.gni")
 import("//build_overrides/nlunit_test.gni")
 
 import("${chip_root}/src/platform/device.gni")
 
 if (chip_device_platform != "none") {
-  import("${chip_root}/build/chip/chip_test_suite.gni")
+  import("${build_root}/chip/chip_test_suite.gni")
 
   chip_test_suite("tests") {
     output_name = "libPlatformTests"
@@ -73,7 +74,7 @@
     }
   }
 } else {
-  import("${chip_root}/build/chip/chip_test_group.gni")
+  import("${build_root}/chip/chip_test_group.gni")
   chip_test_group("tests") {
     deps = []
   }
diff --git a/src/protocols/bdx/tests/BUILD.gn b/src/protocols/bdx/tests/BUILD.gn
index 8cdd90d..cc5e88f 100644
--- a/src/protocols/bdx/tests/BUILD.gn
+++ b/src/protocols/bdx/tests/BUILD.gn
@@ -12,11 +12,12 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import("//build_overrides/build.gni")
 import("//build_overrides/chip.gni")
 import("//build_overrides/nlio.gni")
 import("//build_overrides/nlunit_test.gni")
 
-import("${chip_root}/build/chip/chip_test_suite.gni")
+import("${build_root}/chip/chip_test_suite.gni")
 
 chip_test_suite("tests") {
   output_name = "libBDXTests"
diff --git a/src/qrcodetool/BUILD.gn b/src/qrcodetool/BUILD.gn
index 4ebbd90..8d54994 100644
--- a/src/qrcodetool/BUILD.gn
+++ b/src/qrcodetool/BUILD.gn
@@ -12,9 +12,10 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import("//build_overrides/build.gni")
 import("//build_overrides/chip.gni")
 
-import("${chip_root}/build/chip/tools.gni")
+import("${build_root}/chip/tools.gni")
 
 assert(chip_build_tools)
 
diff --git a/src/setup_payload/java/BUILD.gn b/src/setup_payload/java/BUILD.gn
index 57b21bb..9a486eb 100644
--- a/src/setup_payload/java/BUILD.gn
+++ b/src/setup_payload/java/BUILD.gn
@@ -12,10 +12,11 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import("//build_overrides/build.gni")
 import("//build_overrides/chip.gni")
 
-import("//build/config/android_abi.gni")
-import("${chip_root}/build/chip/java/rules.gni")
+import("${build_root}/chip/java/rules.gni")
+import("${build_root}/config/android_abi.gni")
 
 shared_library("jni") {
   output_name = "libSetupPayloadParser"
@@ -35,7 +36,7 @@
 
   data_deps = [
     ":jni",
-    "//build/chip/java:shared_cpplib",
+    "${build_root}/chip/java:shared_cpplib",
   ]
 
   sources = [
diff --git a/src/setup_payload/tests/BUILD.gn b/src/setup_payload/tests/BUILD.gn
index 06da973..10d7b83 100644
--- a/src/setup_payload/tests/BUILD.gn
+++ b/src/setup_payload/tests/BUILD.gn
@@ -12,10 +12,11 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import("//build_overrides/build.gni")
 import("//build_overrides/chip.gni")
 import("//build_overrides/nlunit_test.gni")
 
-import("${chip_root}/build/chip/chip_test_suite.gni")
+import("${build_root}/chip/chip_test_suite.gni")
 
 chip_test_suite("tests") {
   output_name = "libSetupPayloadTests"
diff --git a/src/system/BUILD.gn b/src/system/BUILD.gn
index 044aa74..fa68ca5 100644
--- a/src/system/BUILD.gn
+++ b/src/system/BUILD.gn
@@ -12,12 +12,13 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import("//build_overrides/build.gni")
 import("//build_overrides/chip.gni")
 import("//build_overrides/nlassert.gni")
 import("//build_overrides/nlfaultinjection.gni")
 
-import("${chip_root}/build/chip/buildconfig_header.gni")
-import("${chip_root}/build/chip/tests.gni")
+import("${build_root}/chip/buildconfig_header.gni")
+import("${build_root}/chip/tests.gni")
 import("${chip_root}/src/platform/device.gni")
 import("system.gni")
 
diff --git a/src/system/tests/BUILD.gn b/src/system/tests/BUILD.gn
index 0a0c8bf..496e13d 100644
--- a/src/system/tests/BUILD.gn
+++ b/src/system/tests/BUILD.gn
@@ -12,10 +12,11 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import("//build_overrides/build.gni")
 import("//build_overrides/chip.gni")
 import("//build_overrides/nlunit_test.gni")
 
-import("${chip_root}/build/chip/chip_test_suite.gni")
+import("${build_root}/chip/chip_test_suite.gni")
 
 chip_test_suite("tests") {
   output_name = "libSystemLayerTests"
diff --git a/src/test_driver/happy/tests/standalone/inet/BUILD.gn b/src/test_driver/happy/tests/standalone/inet/BUILD.gn
index 7562c1d..0d7dafe 100644
--- a/src/test_driver/happy/tests/standalone/inet/BUILD.gn
+++ b/src/test_driver/happy/tests/standalone/inet/BUILD.gn
@@ -12,9 +12,10 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import("//build_overrides/build.gni")
 import("//build_overrides/chip.gni")
 
-import("${chip_root}/build/chip/happy_test.gni")
+import("${build_root}/chip/happy_test.gni")
 
 happy_test("inet_tests") {
   deps = [ "${chip_root}/src/inet/tests:happy_tests" ]
diff --git a/src/transport/raw/tests/BUILD.gn b/src/transport/raw/tests/BUILD.gn
index 3fa3ba2..5c96279 100644
--- a/src/transport/raw/tests/BUILD.gn
+++ b/src/transport/raw/tests/BUILD.gn
@@ -12,11 +12,12 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import("//build_overrides/build.gni")
 import("//build_overrides/chip.gni")
 import("//build_overrides/nlio.gni")
 import("//build_overrides/nlunit_test.gni")
 
-import("${chip_root}/build/chip/chip_test_suite.gni")
+import("${build_root}/chip/chip_test_suite.gni")
 
 static_library("helpers") {
   output_name = "libNetworkTestHelpers"
diff --git a/src/transport/retransmit/tests/BUILD.gn b/src/transport/retransmit/tests/BUILD.gn
index 2872fb2..4ae6381 100644
--- a/src/transport/retransmit/tests/BUILD.gn
+++ b/src/transport/retransmit/tests/BUILD.gn
@@ -12,11 +12,12 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import("//build_overrides/build.gni")
 import("//build_overrides/chip.gni")
 import("//build_overrides/nlio.gni")
 import("//build_overrides/nlunit_test.gni")
 
-import("${chip_root}/build/chip/chip_test_suite.gni")
+import("${build_root}/chip/chip_test_suite.gni")
 
 chip_test_suite("tests") {
   output_name = "libRetransmitTests"
diff --git a/src/transport/tests/BUILD.gn b/src/transport/tests/BUILD.gn
index ad4c6c5..e90ae59 100644
--- a/src/transport/tests/BUILD.gn
+++ b/src/transport/tests/BUILD.gn
@@ -12,11 +12,12 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import("//build_overrides/build.gni")
 import("//build_overrides/chip.gni")
 import("//build_overrides/nlio.gni")
 import("//build_overrides/nlunit_test.gni")
 
-import("${chip_root}/build/chip/chip_test_suite.gni")
+import("${build_root}/chip/chip_test_suite.gni")
 
 chip_test_suite("tests") {
   output_name = "libTransportLayerTests"
diff --git a/third_party/efr32_sdk/efr32_executable.gni b/third_party/efr32_sdk/efr32_executable.gni
index e0bb695..62934cc 100644
--- a/third_party/efr32_sdk/efr32_executable.gni
+++ b/third_party/efr32_sdk/efr32_executable.gni
@@ -12,7 +12,10 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-import("//build/toolchain/flashable_executable.gni")
+import("//build_overrides/build.gni")
+import("//build_overrides/chip.gni")
+
+import("${build_root}/toolchain/flashable_executable.gni")
 
 template("efr32_executable") {
   output_base_name = get_path_info(invoker.output_name, "name")
diff --git a/third_party/jlink/segger_rtt/RTT/BUILD.gn b/third_party/jlink/segger_rtt/RTT/BUILD.gn
index fd2769b..041345e 100644
--- a/third_party/jlink/segger_rtt/RTT/BUILD.gn
+++ b/third_party/jlink/segger_rtt/RTT/BUILD.gn
@@ -12,10 +12,11 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-import("//build/config/arm.gni")
+import("//build_overrides/build.gni")
 import("//build_overrides/chip.gni")
 
-import("${chip_root}/build/chip/buildconfig_header.gni")
+import("${build_root}/config/arm.gni")
+import("${build_root}/chip/buildconfig_header.gni")
 
 declare_args() {
   # Size of SEGGER RTT up buffer.
diff --git a/third_party/k32w_sdk/k32w_executable.gni b/third_party/k32w_sdk/k32w_executable.gni
index 205176e..0c914a3 100644
--- a/third_party/k32w_sdk/k32w_executable.gni
+++ b/third_party/k32w_sdk/k32w_executable.gni
@@ -12,7 +12,10 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-import("//build/toolchain/flashable_executable.gni")
+import("//build_overrides/build.gni")
+import("//build_overrides/chip.gni")
+
+import("${build_root}/toolchain/flashable_executable.gni")
 
 template("k32w_executable") {
   output_base_name = get_path_info(invoker.output_name, "name")
diff --git a/third_party/ot-br-posix/BUILD.gn b/third_party/ot-br-posix/BUILD.gn
index fbaec5d..d16f4a1 100644
--- a/third_party/ot-br-posix/BUILD.gn
+++ b/third_party/ot-br-posix/BUILD.gn
@@ -12,9 +12,11 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-import("//build/config/linux/pkg_config.gni")
+import("//build_overrides/build.gni")
 import("//build_overrides/chip.gni")
 
+import("${build_root}/config/linux/pkg_config.gni")
+
 config("ot_br_client_config") {
   # Treat these includes as system includes, so warnings in them are not fatal.
   _include_dirs = [
diff --git a/third_party/pigweed/repo b/third_party/pigweed/repo
index f908035..293e1c1 160000
--- a/third_party/pigweed/repo
+++ b/third_party/pigweed/repo
@@ -1 +1 @@
-Subproject commit f908035232502461cc4bb5259ac1c6d24293707b
+Subproject commit 293e1c16d1096fd9c6db800c14a97bcef21ec66f
diff --git a/third_party/qpg_sdk/qpg6100_executable.gni b/third_party/qpg_sdk/qpg6100_executable.gni
index eced74a..52fcbe1 100644
--- a/third_party/qpg_sdk/qpg6100_executable.gni
+++ b/third_party/qpg_sdk/qpg6100_executable.gni
@@ -12,7 +12,10 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-import("//build/toolchain/flashable_executable.gni")
+import("//build_overrides/build.gni")
+import("//build_overrides/chip.gni")
+
+import("${build_root}/toolchain/flashable_executable.gni")
 
 template("qpg6100_executable") {
   output_base_name = get_path_info(invoker.output_name, "name")
diff --git a/third_party/ti_simplelink_sdk/ti_simplelink_executable.gni b/third_party/ti_simplelink_sdk/ti_simplelink_executable.gni
index 0392032..f7ce948 100644
--- a/third_party/ti_simplelink_sdk/ti_simplelink_executable.gni
+++ b/third_party/ti_simplelink_sdk/ti_simplelink_executable.gni
@@ -12,7 +12,9 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-import("//build/toolchain/flashable_executable.gni")
+import("//build_overrides/build.gni")
+
+import("${build_root}/toolchain/flashable_executable.gni")
 
 template("ti_simplelink_executable") {
   # we really only need the ELF
diff --git a/third_party/ti_simplelink_sdk/ti_simplelink_sdk.gni b/third_party/ti_simplelink_sdk/ti_simplelink_sdk.gni
index c444ba0..8d82ed4 100644
--- a/third_party/ti_simplelink_sdk/ti_simplelink_sdk.gni
+++ b/third_party/ti_simplelink_sdk/ti_simplelink_sdk.gni
@@ -12,6 +12,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import("//build_overrides/build.gni")
 import("//build_overrides/chip.gni")
 import("//build_overrides/freertos.gni")
 import("//build_overrides/mbedtls.gni")
@@ -183,7 +184,7 @@
     include_dirs = []
 
     # POSIX-like porting layer is incompatable with the gnu definitions from -std=gnu11
-    configs -= [ "//build/config/compiler:std_default" ]
+    configs -= [ "${build_root}/config/compiler:std_default" ]
     configs += [ ":${sdk_target_name}_posix_config" ]
     sources = [
       "${ti_simplelink_sdk_root}/source/ti/posix/freertos/clock.c",
@@ -228,7 +229,7 @@
       "${chip_root}/third_party/ti_simplelink_sdk:ti_simplelink_sysconfig",
     ]
 
-    configs -= [ "//build/config/compiler:std_default" ]
+    configs -= [ "${build_root}/config/compiler:std_default" ]
     configs += [ ":${sdk_target_name}_posix_config" ]
     sources = [
       "${ti_simplelink_sdk_root}/examples/rtos/${ti_simplelink_board}/thread/cli_mtd/platform/alarm.c",