New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added initial C support to configfile.h, extension.h and resource.h #7889
base: dev
Are you sure you want to change the base?
Conversation
# Conflicts: # engine/extension/src/dmsdk/extension/extension.h
# Conflicts: # engine/liveupdate/src/liveupdate.cpp # share/extender/build_input.yml
# Conflicts: # engine/dlib/src/dmsdk/dlib/configfile.h # engine/extension/src/dmsdk/extension/extension.h # engine/extension/src/extension.cpp
@@ -0,0 +1,166 @@ | |||
;; Copyright 2020-2023 The Defold Foundation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an old branch, originally created for the Zig example/presentation
@@ -0,0 +1,30 @@ | |||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An example of how we'll generate api files from our C api's.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To regenerate the headers, we'll run:
./scripts/build.py gen_sdk_source
To keep things separated, we use "resource.h" for the C header, "resource.hpp" for the manually crafted C++ header, and "resource_gen.hpp" for the automatically generated header.
These are stored in the repository, as they don't need to be regenerated all the time (although it's currently quick). Another good reason is that it's easier to do hot fixes to the builds while this new workflow is developing.
@@ -30,65 +30,182 @@ | |||
#include "sys.h" | |||
#include "static_assert.h" | |||
|
|||
namespace dmConfigFile | |||
struct ConfigFileEntry |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We still use C++ as the implementation file (at least for now), as it 1) saves time, and 2) we can use containers more easily.
* @typedef | ||
* @name HConfigFile | ||
*/ | ||
typedef struct ConfigFile* HConfigFile; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How new C handles will look like (quite similar to what we do today)
* } | ||
* | ||
*/ | ||
const char* ConfigFileGetString(HConfigFile config, const char* key, const char* default_value); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here the ConfigFile
is the prefix/namespace.
@@ -0,0 +1,260 @@ | |||
/*# Resource |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To keep the resource.h more readable at-a-glance, I moved some of the documentation here.
@@ -0,0 +1,92 @@ | |||
// Copyright 2020-2024 The Defold Foundation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved some of the functionality to separate cpp files for easier reading
c_includes = ['extension.h', | ||
'configfile.h', | ||
'resource.h'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We test build the C api headers using C compiler, to make sure it's strict C code.
# ------------------------------------------------------------ | ||
# Gen source files -> | ||
|
||
def _gen_sdk_source_lib(self, libname, args, cwd, info): | ||
self._log('Generating source for %s' % libname) | ||
libargs = args + ['-i', info] | ||
run.env_command(self._form_env(), libargs, cwd = cwd) | ||
|
||
def gen_sdk_source(self): | ||
print("Generating source!") | ||
cmd = self.get_python() + [os.path.normpath(join(self.defold_root, './scripts/dmsdk/gen_sdk.py'))] | ||
for lib in ENGINE_LIBS: | ||
cwd = 'engine/%s' % lib | ||
info = join(self.defold_root, 'engine/%s/sdk_gen.json' % lib) | ||
if os.path.exists(info): | ||
self._gen_sdk_source_lib(lib, cmd, join(self.defold_root, cwd), info) | ||
|
||
# <- Gen source files | ||
# ------------------------------------------------------------ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the code generation bit from the build.py
@@ -0,0 +1,224 @@ | |||
# Copyright 2020-2024 The Defold Foundation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some of these files are heavily modified from the Sokol bindgen tools.
However, at this point I feel that I've modified it so far, that it has little resemblance of the original scripts.
We've added some first pure C api headers to our
dmSDK
:configfile.h
,extension.h
andresource.h
.This is a step in our current effort to add C# support to our engine.
The old C++ api's should be mostly intact, however we did change passing some structs as pointers (previously passed as references).
While stricly a breaking change for extension developers.
Regular users might not notice it other than that they would have to update an extension version.
dmsdk/dlib/configfile.h
This file now only contains the C api.
For the C++ api, include
dmsdk/dlib/configfile_gen.hpp
dmsdk/extension/extension.h
This file now only contains the C api.
For the C++ api, include
dmsdk/extension/extension_gen.hpp
dmsdk/resource/resource.h
This file now only contains the C api.
For the C++ api, include
dmsdk/resource/resource.hpp
HResourceDescriptor
type and functions.HResourceType
type and functions.Fixes #8924
PR checklist