Add a simple hearder-only library to expose build time flags to C++
This is quite ugly, but will do its job until the build flags are
exposed as aconfig flags. This library will be used by first stage init
to conditionally execute new dice-changes related logic, something along
the lines of:
```
if (IsMicrodroid() && IsAvfOpenDiceChangesEnabled()) {
// run new dice derive binary.
}
```
Bug: 287593065
Test: m
Change-Id: I088e36fed6eb862999f0b0a347a7fc93d69eb9e0
diff --git a/Android.bp b/Android.bp
index f50007f..2091a90 100644
--- a/Android.bp
+++ b/Android.bp
@@ -68,6 +68,7 @@
module_type: "cc_defaults",
config_namespace: "ANDROID",
bool_variables: [
+ "release_avf_enable_dice_changes",
"release_avf_enable_virt_cpufreq",
],
properties: [
@@ -78,6 +79,9 @@
avf_flag_aware_cc_defaults {
name: "avf_build_flags_cc",
soong_config_variables: {
+ release_avf_enable_dice_changes: {
+ cflags: ["-DAVF_OPEN_DICE_CHANGES=1"],
+ },
release_avf_enable_virt_cpufreq: {
cflags: ["-DAVF_ENABLE_VIRT_CPUFREQ=1"],
},
diff --git a/flags/cpp/Android.bp b/flags/cpp/Android.bp
new file mode 100644
index 0000000..da4158a
--- /dev/null
+++ b/flags/cpp/Android.bp
@@ -0,0 +1,13 @@
+cc_library_static {
+ name: "libavf_cc_flags",
+ defaults: ["avf_build_flags_cc"],
+ apex_available: [
+ "//apex_available:platform",
+ "com.android.virt",
+ ],
+
+ export_include_dirs: ["include"],
+ local_include_dirs: ["include"],
+ ramdisk_available: true,
+ recovery_available: true,
+}
diff --git a/flags/cpp/include/android/avf_cc_flags.h b/flags/cpp/include/android/avf_cc_flags.h
new file mode 100644
index 0000000..536ea9f
--- /dev/null
+++ b/flags/cpp/include/android/avf_cc_flags.h
@@ -0,0 +1,31 @@
+// Copyright 2024, The Android Open Source Project
+//
+// 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.
+
+#pragma once
+
+// TODO(b/309090563): remove this file once build flags are exposed to aconfig.
+
+namespace android {
+namespace virtualization {
+
+inline bool IsOpenDiceChangesFlagEnabled() {
+#ifdef AVF_OPEN_DICE_CHANGES
+ return AVF_OPEN_DICE_CHANGES;
+#else
+ return false;
+#endif
+}
+
+} // namespace virtualization
+} // namespace android