godot/editor/editor_build_profile.h
reduz 6236a688b7 Implement Feature Build Profiles
This PR is a continuation of #50381 (which was implemented exactly a year ago!)

* Add a visual interface to select which classes should not be built into Godot (well, they are built if something else uses them, but if not used the optimizer will remove them out).
* Add a detection system to scan the project and figure out the actual classes used.
* Added the ability for SCons to load build profiles.

Obligatory Screen:

A simple test with a couple of nodes in the scene resulted in a 25% reduction for the final binary size

TODO:

* Script languages need to implement used class detection (left for another PR).
* Options to disable servers or server functionalities (like 2D or 3D physics, navigation, etc). Are missing, that should also greatly aid in reducing binary size.
* Options to disable some modules would be desired.
* More options to disable drivers (OpenGL, Vulkan, etc) would be desired.

In general this PR is a starting point for more contributors to improve and enhance this functionality.
2022-07-22 10:53:23 +02:00

174 lines
5.9 KiB
C++

/*************************************************************************/
/* editor_build_profile.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#ifndef EDITOR_BUILD_PROFILE_H
#define EDITOR_BUILD_PROFILE_H
#include "core/io/file_access.h"
#include "core/object/ref_counted.h"
#include "editor/editor_help.h"
#include "scene/gui/dialogs.h"
#include "scene/gui/option_button.h"
#include "scene/gui/separator.h"
#include "scene/gui/split_container.h"
#include "scene/gui/tree.h"
class EditorBuildProfile : public RefCounted {
GDCLASS(EditorBuildProfile, RefCounted);
public:
enum BuildOption {
BUILD_OPTION_3D,
BUILD_OPTION_PHYSICS_2D,
BUILD_OPTION_PHYSICS_3D,
BUILD_OPTION_NAVIGATION,
BUILD_OPTION_XR,
BUILD_OPTION_RENDERING_DEVICE,
BUILD_OPTION_OPENGL,
BUILD_OPTION_VULKAN,
BUILD_OPTION_MAX
};
private:
HashSet<StringName> disabled_classes;
HashSet<StringName> collapsed_classes;
String force_detect_classes;
bool build_options_disabled[BUILD_OPTION_MAX] = {};
static const char *build_option_identifiers[BUILD_OPTION_MAX];
static const bool build_option_disable_values[BUILD_OPTION_MAX];
String _get_build_option_name(BuildOption p_build_option) { return get_build_option_name(p_build_option); }
protected:
static void _bind_methods();
public:
void set_disable_class(const StringName &p_class, bool p_disabled);
bool is_class_disabled(const StringName &p_class) const;
void set_item_collapsed(const StringName &p_class, bool p_collapsed);
bool is_item_collapsed(const StringName &p_class) const;
void set_disable_build_option(BuildOption p_build_option, bool p_disable);
bool is_build_option_disabled(BuildOption p_build_option) const;
void set_force_detect_classes(const String &p_classes);
String get_force_detect_classes() const;
void clear_disabled_classes();
Error save_to_file(const String &p_path);
Error load_from_file(const String &p_path);
static String get_build_option_name(BuildOption p_build_option);
static String get_build_option_description(BuildOption p_build_option);
static bool get_build_option_disable_value(BuildOption p_build_option);
EditorBuildProfile();
};
VARIANT_ENUM_CAST(EditorBuildProfile::BuildOption)
class EditorFileSystemDirectory;
class EditorBuildProfileManager : public AcceptDialog {
GDCLASS(EditorBuildProfileManager, AcceptDialog);
enum Action {
ACTION_NEW,
ACTION_RESET,
ACTION_LOAD,
ACTION_SAVE,
ACTION_SAVE_AS,
ACTION_DETECT,
ACTION_MAX
};
Action last_action = ACTION_NEW;
ConfirmationDialog *confirm_dialog = nullptr;
Button *profile_actions[ACTION_MAX];
Tree *class_list = nullptr;
EditorHelpBit *description_bit = nullptr;
EditorFileDialog *import_profile = nullptr;
EditorFileDialog *export_profile = nullptr;
LineEdit *profile_path = nullptr;
LineEdit *force_detect_classes = nullptr;
void _profile_action(int p_action);
void _action_confirm();
void _update_edited_profile();
void _fill_classes_from(TreeItem *p_parent, const String &p_class, const String &p_selected);
Ref<EditorBuildProfile> edited;
void _import_profile(const String &p_path);
void _export_profile(const String &p_path);
bool updating_build_options = false;
void _class_list_item_selected();
void _class_list_item_edited();
void _class_list_item_collapsed(Object *p_item);
void _detect_classes();
void _force_detect_classes_changed(const String &p_text);
struct DetectedFile {
uint32_t timestamp = 0;
String md5;
Vector<String> classes;
};
void _find_files(EditorFileSystemDirectory *p_dir, const HashMap<String, DetectedFile> &p_cache, HashMap<String, DetectedFile> &r_detected);
static EditorBuildProfileManager *singleton;
protected:
static void _bind_methods();
void _notification(int p_what);
public:
Ref<EditorBuildProfile> get_current_profile();
static EditorBuildProfileManager *get_singleton() { return singleton; }
EditorBuildProfileManager();
};
#endif // EDITOR_BUILD_PROFILE_H