From dd212bbfddd3a8246a8f2a0398d8e32e80fb68d0 Mon Sep 17 00:00:00 2001 From: Robert Paciorek Date: Sat, 1 Jun 2024 09:28:23 +0000 Subject: [PATCH 1/4] fix finding libcef.so on Linux set RPATH to CEF_ARTIFACTS_FOLDER_NAME while build libgdcef.so and gdcefSubProcess --- addons/gdcef/README.md | 6 ------ addons/gdcef/build.py | 12 ++++++------ addons/gdcef/demos/README.md | 9 --------- addons/gdcef/gdcef/SConstruct | 4 ++++ addons/gdcef/subprocess/SConstruct | 5 +++++ 5 files changed, 15 insertions(+), 21 deletions(-) diff --git a/addons/gdcef/README.md b/addons/gdcef/README.md index 191977b..2fc9ade 100644 --- a/addons/gdcef/README.md +++ b/addons/gdcef/README.md @@ -95,12 +95,6 @@ describing the given demos. var browser = $CEF.create_browser("https://github.com/Lecrapouille/gdcef", $TextureRect, {}) browser.get_name("hello") ``` -- In Linux, you will have to write something like: -``` -export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/your/path/gdcef/examples/build -``` - -to make your system finds shared libraries such as `libcef.so`. - You should obtain a minimal CEF browser not reacting to your mouse and key binding. See the 2D and 3D demos to make your browser tab reacts to your input events. diff --git a/addons/gdcef/build.py b/addons/gdcef/build.py index 048c15c..85a2319 100755 --- a/addons/gdcef/build.py +++ b/addons/gdcef/build.py @@ -493,12 +493,12 @@ def run_godot_example(): " into '" + CEF_ARTIFACTS_BUILD_PATH + "' and can be used for your Godot" " project. Do not forget to add .gdns and .gdnlib files refering to libgdcef.so/dll.\n") if OSTYPE == "Linux": - info("For Unix systems you have to make your system know where to find shared" - " libraries needed for CEF. Save the following command in your environment" - " (~/.bashrc i.e.):\n\n" - " export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:" + CEF_ARTIFACTS_BUILD_PATH + "\n" - " export LD_PRELOAD=" + CEF_ARTIFACTS_BUILD_PATH + "/libcef.so\n") - info("Once done, you can run your Godot editor " + GODOT_VERSION + " and try" + info("`" + CEF_ARTIFACTS_FOLDER_NAME + "` path is used to find shared libraries" + " needed for CEF. Put `" + CEF_ARTIFACTS_BUILD_PATH + "` as `" + + CEF_ARTIFACTS_FOLDER_NAME + "` into your project to avoid having to set" + " LD_LIBRARY_PATH environment variable. If you want use other folder name," + " edit value of CEF_ARTIFACTS_FOLDER_NAME in build.py and rebuild project.\n") + info("You can run your Godot editor " + GODOT_VERSION + " and try" " one of the demos located in '" + GDCEF_EXAMPLES_PATH + "'.\n\nHave fun!") ############################################################################### diff --git a/addons/gdcef/demos/README.md b/addons/gdcef/demos/README.md index 69b4d3a..cf59a34 100644 --- a/addons/gdcef/demos/README.md +++ b/addons/gdcef/demos/README.md @@ -18,15 +18,6 @@ No command line is needed. This script will: **Workaround For Windows:** You need **x64 Native Tools Command Prompt for VS 2022**, with **Administrator** privilege! -**Workaround For Linux:** for the moment, the `libcef.so` and other shared libraries, -as artifcats, are not found by the systeme (even if indicated in the `.gdnlib` file. -So for the moment, you have to store the path of the `build` in your `LD_LIBRARY_PATH` -(for example in your `~/.bashrc` file). - -``` -export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/your/path/gdcef/examples/build -``` - **Note concerning the build folder**: CEF artifcats are searched inside the `build` folder at the root of your Godot project. diff --git a/addons/gdcef/gdcef/SConstruct b/addons/gdcef/gdcef/SConstruct index be9a5d3..9442832 100644 --- a/addons/gdcef/gdcef/SConstruct +++ b/addons/gdcef/gdcef/SConstruct @@ -214,6 +214,10 @@ env.Append(LIBS = [libcef, 'libcef_dll_wrapper'], # Pathes header files of our module env.Append(CPPPATH=['src/']) +# Add artifacts folder to (embedded into output binary file) list of paths to search for shared libraries +# [2:-2] because we need value of cef_artifacts_folder without protected quotation marks +env.Append(RPATH=[env['cef_artifacts_folder'][2:-2]]) + # Compile the library sources = ['src/helper_files.cpp', 'src/browser_io.cpp', 'src/gdcef.cpp', 'src/gdbrowser.cpp', 'src/register_types.cpp'] # sources = Glob('src/*.cpp') diff --git a/addons/gdcef/subprocess/SConstruct b/addons/gdcef/subprocess/SConstruct index a55f086..cc3a5e2 100644 --- a/addons/gdcef/subprocess/SConstruct +++ b/addons/gdcef/subprocess/SConstruct @@ -48,6 +48,7 @@ opts.Add(EnumVariable('arch', 'Platform architecture', 'x86_64', ['x86_64', 'arm opts.Add(BoolVariable('use_llvm', 'Use the LLVM / Clang compiler', 'no')) opts.Add(PathVariable('api_path', 'Godot C++ API', '')) opts.Add(PathVariable('build_path', 'Build path', '')) +opts.Add(PathVariable('cef_artifacts_folder', 'CEF artifacts folder', '', PathVariable.PathAccept)) # Updates the environment with the option variables. opts.Update(env) @@ -204,6 +205,10 @@ env.Append(LIBS = [libcef, 'libcef_dll_wrapper'], # Pathes header files of our module env.Append(CPPPATH=['src/']) +# Add artifacts folder to (embedded into output binary file) list of paths to search for shared libraries +# [2:-2] because we need value of cef_artifacts_folder without protected quotation marks +env.Append(RPATH=[env['cef_artifacts_folder'][2:-2]]) + # Compile the application sources = Glob('src/*.cpp') application = env.Program(target=target_path + '/' + target_binary, source=sources) From 174ff3191a24b9dc5e81a889282bcfd5fbdba44f Mon Sep 17 00:00:00 2001 From: Robert Paciorek Date: Sat, 1 Jun 2024 09:40:22 +0000 Subject: [PATCH 2/4] autogenerate .gdextension file with correct path --- addons/gdcef/build.py | 14 +++++++++++--- addons/gdcef/demos/2D/libs/gdcef.gdextension | 17 ----------------- addons/gdcef/demos/3D/libs/gdcef.gdextension | 17 ----------------- .../gdcef/demos/HelloCEF/libs/gdcef.gdextension | 17 ----------------- addons/gdcef/gdcef/gdcef.gdextension.in | 17 +++++++++++++++++ 5 files changed, 28 insertions(+), 54 deletions(-) delete mode 100644 addons/gdcef/demos/2D/libs/gdcef.gdextension delete mode 100644 addons/gdcef/demos/3D/libs/gdcef.gdextension delete mode 100644 addons/gdcef/demos/HelloCEF/libs/gdcef.gdextension create mode 100644 addons/gdcef/gdcef/gdcef.gdextension.in diff --git a/addons/gdcef/build.py b/addons/gdcef/build.py index 85a2319..a864f4c 100755 --- a/addons/gdcef/build.py +++ b/addons/gdcef/build.py @@ -54,9 +54,7 @@ CEF_BUILD_FOLDER_NAME = "build" # When we are compiling demos we are creating a folder holding CEF build artifacts. # But, in the aim to save space on your hard disk the folder is a pointer to folder -# CEF_ARTIFACTS_BUILD_PATH. If you modify this variable, do not forget to also change -# Godot .gdns and .gdnlib files inside the libs folders in GDCEF_EXAMPLES_PATH the -# demos folder. +# CEF_ARTIFACTS_BUILD_PATH. CEF_ARTIFACTS_FOLDER_NAME = "cef_artifacts" # Use OpenMP for using CPU parallelim (i.e. for copying textures) CEF_USE_CPU_PARALLELISM = "yes" # or "no" @@ -427,6 +425,15 @@ def compile_gdnative_cef(path): else: fatal("Unknown archi " + OSTYPE + ": I dunno how to compile CEF module primary process") +############################################################################### +### Compile Godot CEF module named GDCef and its subprocess +def create_gdextension_file(): + info("Create Godot .gdextension file") + with open(os.path.join(GDCEF_PATH, "gdcef.gdextension.in"), "r") as f: + extension = f.read().replace("CEF_ARTIFACTS_FOLDER_NAME", CEF_ARTIFACTS_FOLDER_NAME) + with open(os.path.join(CEF_ARTIFACTS_BUILD_PATH, "gdcef.gdextension"), "w") as f: + f.write(extension) + ############################################################################### ### Check if compilers are present (Windows) def check_compiler(): @@ -514,5 +521,6 @@ def run_godot_example(): install_cef_assets() compile_gdnative_cef(GDCEF_PATH) compile_gdnative_cef(GDCEF_PROCESSES_PATH) + create_gdextension_file() prepare_godot_examples() run_godot_example() diff --git a/addons/gdcef/demos/2D/libs/gdcef.gdextension b/addons/gdcef/demos/2D/libs/gdcef.gdextension deleted file mode 100644 index 1aee141..0000000 --- a/addons/gdcef/demos/2D/libs/gdcef.gdextension +++ /dev/null @@ -1,17 +0,0 @@ -[configuration] -entry_symbol = "gdcef_library_init" -compatibility_minimum = 4.1 - -[libraries] -linux.x86_64.debug = "res://cef_artifacts/libgdcef.so" -linux.x86_64.release = "res://cef_artifacts/libgdcef.so" -linux.x86_32.debug = "res://cef_artifacts/libgdcef.so" -linux.x86_32.release = "res://cef_artifacts/libgdcef.so" - -windows.x86_64.debug = "res://cef_artifacts/libgdcef.dll" -windows.x86_64.release = "res://cef_artifacts/libgdcef.dll" -windows.x86_32.debug = "res://cef_artifacts/libgdcef.dll" -windows.x86_32.release = "res://cef_artifacts/libgdcef.dll" - -macos.debug = "res://cef_artifacts/Frameworks/Chromium\ Embedded\ Framework.framework/Libraries/libgdcef.dylib" -macos.release = "res://cef_artifacts/Frameworks/Chromium\ Embedded\ Framework.framework/Libraries/libgdcef.dylib" diff --git a/addons/gdcef/demos/3D/libs/gdcef.gdextension b/addons/gdcef/demos/3D/libs/gdcef.gdextension deleted file mode 100644 index 1aee141..0000000 --- a/addons/gdcef/demos/3D/libs/gdcef.gdextension +++ /dev/null @@ -1,17 +0,0 @@ -[configuration] -entry_symbol = "gdcef_library_init" -compatibility_minimum = 4.1 - -[libraries] -linux.x86_64.debug = "res://cef_artifacts/libgdcef.so" -linux.x86_64.release = "res://cef_artifacts/libgdcef.so" -linux.x86_32.debug = "res://cef_artifacts/libgdcef.so" -linux.x86_32.release = "res://cef_artifacts/libgdcef.so" - -windows.x86_64.debug = "res://cef_artifacts/libgdcef.dll" -windows.x86_64.release = "res://cef_artifacts/libgdcef.dll" -windows.x86_32.debug = "res://cef_artifacts/libgdcef.dll" -windows.x86_32.release = "res://cef_artifacts/libgdcef.dll" - -macos.debug = "res://cef_artifacts/Frameworks/Chromium\ Embedded\ Framework.framework/Libraries/libgdcef.dylib" -macos.release = "res://cef_artifacts/Frameworks/Chromium\ Embedded\ Framework.framework/Libraries/libgdcef.dylib" diff --git a/addons/gdcef/demos/HelloCEF/libs/gdcef.gdextension b/addons/gdcef/demos/HelloCEF/libs/gdcef.gdextension deleted file mode 100644 index 1aee141..0000000 --- a/addons/gdcef/demos/HelloCEF/libs/gdcef.gdextension +++ /dev/null @@ -1,17 +0,0 @@ -[configuration] -entry_symbol = "gdcef_library_init" -compatibility_minimum = 4.1 - -[libraries] -linux.x86_64.debug = "res://cef_artifacts/libgdcef.so" -linux.x86_64.release = "res://cef_artifacts/libgdcef.so" -linux.x86_32.debug = "res://cef_artifacts/libgdcef.so" -linux.x86_32.release = "res://cef_artifacts/libgdcef.so" - -windows.x86_64.debug = "res://cef_artifacts/libgdcef.dll" -windows.x86_64.release = "res://cef_artifacts/libgdcef.dll" -windows.x86_32.debug = "res://cef_artifacts/libgdcef.dll" -windows.x86_32.release = "res://cef_artifacts/libgdcef.dll" - -macos.debug = "res://cef_artifacts/Frameworks/Chromium\ Embedded\ Framework.framework/Libraries/libgdcef.dylib" -macos.release = "res://cef_artifacts/Frameworks/Chromium\ Embedded\ Framework.framework/Libraries/libgdcef.dylib" diff --git a/addons/gdcef/gdcef/gdcef.gdextension.in b/addons/gdcef/gdcef/gdcef.gdextension.in new file mode 100644 index 0000000..3b8b171 --- /dev/null +++ b/addons/gdcef/gdcef/gdcef.gdextension.in @@ -0,0 +1,17 @@ +[configuration] +entry_symbol = "gdcef_library_init" +compatibility_minimum = 4.1 + +[libraries] +linux.x86_64.debug = "res://CEF_ARTIFACTS_FOLDER_NAME/libgdcef.so" +linux.x86_64.release = "res://CEF_ARTIFACTS_FOLDER_NAME/libgdcef.so" +linux.x86_32.debug = "res://CEF_ARTIFACTS_FOLDER_NAME/libgdcef.so" +linux.x86_32.release = "res://CEF_ARTIFACTS_FOLDER_NAME/libgdcef.so" + +windows.x86_64.debug = "res://CEF_ARTIFACTS_FOLDER_NAME/libgdcef.dll" +windows.x86_64.release = "res://CEF_ARTIFACTS_FOLDER_NAME/libgdcef.dll" +windows.x86_32.debug = "res://CEF_ARTIFACTS_FOLDER_NAME/libgdcef.dll" +windows.x86_32.release = "res://CEF_ARTIFACTS_FOLDER_NAME/libgdcef.dll" + +macos.debug = "res://CEF_ARTIFACTS_FOLDER_NAME/Frameworks/Chromium\ Embedded\ Framework.framework/Libraries/libgdcef.dylib" +macos.release = "res://CEF_ARTIFACTS_FOLDER_NAME/Frameworks/Chromium\ Embedded\ Framework.framework/Libraries/libgdcef.dylib" From ad22218744296e547530de814facc7ea7eb23959 Mon Sep 17 00:00:00 2001 From: Robert Paciorek Date: Sat, 1 Jun 2024 09:43:26 +0000 Subject: [PATCH 3/4] use default resource_path in demos this allow run unmodified demos while using custom value of CEF_ARTIFACTS_BUILD_PATH --- addons/gdcef/demos/2D/CEF.gd | 2 -- addons/gdcef/demos/3D/GUI.gd | 3 +-- addons/gdcef/demos/HelloCEF/Control.gd | 3 +-- 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/addons/gdcef/demos/2D/CEF.gd b/addons/gdcef/demos/2D/CEF.gd index 80b89c4..d3cdff6 100644 --- a/addons/gdcef/demos/2D/CEF.gd +++ b/addons/gdcef/demos/2D/CEF.gd @@ -331,9 +331,7 @@ func _ready(): # artifacts: allows path such as "build" or "res://cef_artifacts/". Note that "res://" # will use ProjectSettings.globalize_path but exported projects don't support globalize_path: # https://docs.godotengine.org/en/3.5/classes/class_projectsettings.html#class-projectsettings-method-globalize-path - var resource_path = "res://cef_artifacts/" if !$CEF.initialize({ - "artifacts":resource_path, "incognito":true, "locale":"en-US", "enable_media_stream": true diff --git a/addons/gdcef/demos/3D/GUI.gd b/addons/gdcef/demos/3D/GUI.gd index 7eeb2ba..3062135 100644 --- a/addons/gdcef/demos/3D/GUI.gd +++ b/addons/gdcef/demos/3D/GUI.gd @@ -148,8 +148,7 @@ func _ready(): # artifacts: allows path such as "build" or "res://cef_artifacts/". Note that "res://" # will use ProjectSettings.globalize_path but exported projects don't support globalize_path: # https://docs.godotengine.org/en/3.5/classes/class_projectsettings.html#class-projectsettings-method-globalize-path - var resource_path = "res://cef_artifacts/" - if !$CEF.initialize({"artifacts":resource_path, "incognito":true, "locale":"en-US"}): + if !$CEF.initialize({"incognito":true, "locale":"en-US"}): push_error($CEF.get_error()) get_tree().quit() return diff --git a/addons/gdcef/demos/HelloCEF/Control.gd b/addons/gdcef/demos/HelloCEF/Control.gd index 185025d..3db9081 100644 --- a/addons/gdcef/demos/HelloCEF/Control.gd +++ b/addons/gdcef/demos/HelloCEF/Control.gd @@ -161,8 +161,7 @@ func _ready(): # artifacts: allows path such as "build" or "res://cef_artifacts/". Note that "res://" # will use ProjectSettings.globalize_path but exported projects don't support globalize_path: # https://docs.godotengine.org/en/3.5/classes/class_projectsettings.html#class-projectsettings-method-globalize-path - var resource_path = "res://cef_artifacts/" - if !$CEF.initialize({"artifacts":resource_path, "incognito":true, "locale":"en-US"}): + if !$CEF.initialize({"incognito":true, "locale":"en-US"}): push_error("Failed initializing CEF") get_tree().quit() else: From f2941c06aa380fbd6b4e364bbdfd7df642ef5a1b Mon Sep 17 00:00:00 2001 From: Robert Paciorek Date: Sat, 1 Jun 2024 09:53:36 +0000 Subject: [PATCH 4/4] create parent dirs for CEF_ARTIFACTS_FOLDER_NAME this allow use subdirectory as CEF_ARTIFACTS_FOLDER_NAME (like "addons/gdcef") --- addons/gdcef/build.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/addons/gdcef/build.py b/addons/gdcef/build.py index a864f4c..0665644 100755 --- a/addons/gdcef/build.py +++ b/addons/gdcef/build.py @@ -491,7 +491,9 @@ def prepare_godot_examples(): path = os.path.join(GDCEF_EXAMPLES_PATH, filename) if os.path.isdir(path) and os.path.isfile(os.path.join(path, "project.godot")): info(" - Demo " + path) - symlink(CEF_ARTIFACTS_BUILD_PATH, os.path.join(path, CEF_ARTIFACTS_FOLDER_NAME)) + artifacts_path = os.path.join(path, CEF_ARTIFACTS_FOLDER_NAME) + mkdir(os.path.dirname(artifacts_path)) + symlink(CEF_ARTIFACTS_BUILD_PATH, artifacts_path) ############################################################################### ### Run Godot example