diff --git a/Config/Bindings.toml b/Config/Bindings.toml new file mode 100644 index 0000000..fbd8584 --- /dev/null +++ b/Config/Bindings.toml @@ -0,0 +1,113 @@ +# This is a template cbindgen.toml file with all of the default values. +# Some values are commented out because their absence is the real default. +# +# See https://github.com/eqrion/cbindgen/blob/master/docs.md#cbindgentoml +# for detailed documentation of every option here. + +language = "C" + +############## Options for Wrapping the Contents of the Header ################# + +header = "// Copyright (c) TribuFu. All Rights Reserved" +# trailer = "/* Text to put at the end of the generated file */" +# include_guard = "my_bindings_h" +pragma_once = true +# autogen_warning = "/* Warning, this file is autogenerated by cbindgen. Don't modify this manually. */" +include_version = false +namespace = "TribuFu" +namespaces = [] +using_namespaces = [] +sys_includes = [] +includes = [] +no_includes = false +cpp_compat = true + +# A list of lines to add verbatim after the includes block +after_includes = "\n#define TRIBUFU_SDK 1" + +############################ Code Style Options ################################ + +braces = "NextLine" +line_length = 100 +tab_width = 4 +line_endings = "LF" # also "CR", "CRLF", "Native" + +############################# Codegen Options ################################## + +style = "tag" +sort_by = "Name" # default for `fn.sort_by` and `const.sort_by` +usize_is_size_t = true + +[defines] +# "target_os = freebsd" = "DEFINE_FREEBSD" +# "feature = serde" = "DEFINE_SERDE" + +[export] +include = [] +exclude = [] +# prefix = "CAPI_" +item_types = [] +renaming_overrides_prefixing = false + +[export.rename] + +[export.body] + +[export.mangle] + +[fn] +# rename_args = "PascalCase" +# must_use = "MUST_USE_FUNC" +# no_return = "NO_RETURN" +# prefix = "START_FUNC" +# postfix = "END_FUNC" +args = "auto" +sort_by = "Name" + +[struct] +# rename_fields = "PascalCase" +# must_use = "MUST_USE_STRUCT" +derive_constructor = false +derive_eq = false +derive_neq = false +derive_lt = false +derive_lte = false +derive_gt = false +derive_gte = false + +[enum] +# rename_variants = "PascalCase" +# must_use = "MUST_USE_ENUM" +add_sentinel = false +prefix_with_name = false +derive_helper_methods = false +derive_const_casts = false +derive_mut_casts = false +# cast_assert_name = "ASSERT" +derive_tagged_enum_destructor = false +derive_tagged_enum_copy_constructor = false +enum_class = true +private_default_tagged_enum_constructor = false + +[const] +allow_static_const = true +allow_constexpr = false +sort_by = "Name" + +[macro_expansion] +bitflags = false + +############## Options for How Your Rust library Should Be Parsed ############## + +[parse] +parse_deps = false +# include = [] +exclude = [] +clean = false +extra_bindings = [] + +[parse.expand] +crates = [] +all_features = false +default_features = true +features = [] diff --git a/Examples/C/Hello.c b/Examples/C/Hello.c new file mode 100644 index 0000000..061e899 --- /dev/null +++ b/Examples/C/Hello.c @@ -0,0 +1,12 @@ +// Copyright (c) TribuFu. All Rights Reserved + +#include "stdio.h" + +#include "TribuFu.h" + +extern int32_t Hello(void); + +int main() +{ + printf("TribuFu SDK = %d\n", Hello()); +} diff --git a/Examples/CSharp/Hello.cs b/Examples/CSharp/Hello.cs new file mode 100644 index 0000000..d820216 --- /dev/null +++ b/Examples/CSharp/Hello.cs @@ -0,0 +1,24 @@ +// Copyright (c) TribuFu. All Rights Reserved + +using System; +using System.Runtime.InteropServices; + +namespace CSharp +{ + class Program + { + #if WINDOWS_PLATFORM + const string TribuFu = "TribuFu"; + #else + const string TribuFu = "libTribuFu"; + #endif + + [DllImport(TribuFu)] + public static extern int Hello(); + + public static void Main(string[] args) + { + Console.WriteLine("TribuFu SDK = " + Hello()); + } + } +} diff --git a/Examples/Cpp/Hello.cpp b/Examples/Cpp/Hello.cpp new file mode 100644 index 0000000..2b22e97 --- /dev/null +++ b/Examples/Cpp/Hello.cpp @@ -0,0 +1,14 @@ +// Copyright (c) TribuFu. All Rights Reserved + +#include + +#include "TribuFu.h" + +using namespace std; + +extern int32_t Hello(); + +int main() +{ + cout << "TribuFu SDK = " << (int)TribuFu::Hello() << "\n"; +} diff --git a/GenerateProjectFiles.bat b/GenerateProjectFiles.bat new file mode 100644 index 0000000..675456c --- /dev/null +++ b/GenerateProjectFiles.bat @@ -0,0 +1,2 @@ +cbindgen --config .\Config\Bindings.toml --crate TribuFu --output Source\Header.h +call .\Vendor\Premake\Windows\premake5.exe vs2019 diff --git a/GenerateProjectFiles.command b/GenerateProjectFiles.command new file mode 100644 index 0000000..363f400 --- /dev/null +++ b/GenerateProjectFiles.command @@ -0,0 +1,4 @@ +#!/bin/zsh + +cbindgen --config ./Config/Bindings.toml --crate TribuFu --output Source/Header.h +sudo ./Vendor/Premake/Mac/premake5 xcode4 diff --git a/GenerateProjectFiles.sh b/GenerateProjectFiles.sh new file mode 100644 index 0000000..56e9e09 --- /dev/null +++ b/GenerateProjectFiles.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +cbindgen --config ./Config/Bindings.toml --crate TribuFu --output Source/Header.h +sudo ./Vendor/Premake/Linux/premake5 gmake2 diff --git a/Source/TribuFu.h b/Source/TribuFu.h new file mode 100644 index 0000000..1bffd29 --- /dev/null +++ b/Source/TribuFu.h @@ -0,0 +1,61 @@ +// Copyright (c) TribuFu. All Rights Reserved + +#pragma once + +#include +#include +#include +#include +#include + +#define TRIBUFU_SDK 1 + +#ifdef __cplusplus +namespace TribuFu +{ +#endif + +#ifdef __cplusplus + extern "C" + { +#endif + + void AcceptFriend(const char *id1, const char *id2); + + void AddFriend(const char *id1, const char *id2); + + void EnterTeam(void); + + void GetDevice(const char *id); + + void GetFriends(const char *id); + + void GetMessage(const char *id); + + void GetRole(const char *id); + + void GetUser(const char *id); + + void GetUserDevices(const char *id); + + void GetUserRoles(const char *id); + + int32_t Hello(void); + + void InviteToTeam(void); + + void Login(const char *name, const char *password); + + void Logout(void); + + void Refresh(void); + + void Register(const char *name, const char *email, const char *password); + +#ifdef __cplusplus + } +#endif + +#ifdef __cplusplus +} +#endif diff --git a/Vendor/Premake/LICENSE.txt b/Vendor/Premake/LICENSE.txt new file mode 100644 index 0000000..f445f59 --- /dev/null +++ b/Vendor/Premake/LICENSE.txt @@ -0,0 +1,27 @@ +Copyright (c) 2003-2019 Jason Perkins and individual contributors. +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + 3. Neither the name of Premake nor the names of its contributors may be + used to endorse or promote products derived from this software without + specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/Vendor/Premake/Linux/premake5 b/Vendor/Premake/Linux/premake5 new file mode 100644 index 0000000..2fd412d Binary files /dev/null and b/Vendor/Premake/Linux/premake5 differ diff --git a/Vendor/Premake/Mac/premake5 b/Vendor/Premake/Mac/premake5 new file mode 100644 index 0000000..d192618 Binary files /dev/null and b/Vendor/Premake/Mac/premake5 differ diff --git a/Vendor/Premake/Windows/premake5.exe b/Vendor/Premake/Windows/premake5.exe new file mode 100644 index 0000000..f081fe1 Binary files /dev/null and b/Vendor/Premake/Windows/premake5.exe differ diff --git a/Vendor/rcedit.exe b/Vendor/rcedit.exe new file mode 100644 index 0000000..36764c6 Binary files /dev/null and b/Vendor/rcedit.exe differ diff --git a/premake5.lua b/premake5.lua new file mode 100644 index 0000000..dec0093 --- /dev/null +++ b/premake5.lua @@ -0,0 +1,138 @@ +workspace "TribuFu" + architecture "x64" + + configurations + { + "debug", + "release" + } + +outputDir = "%{cfg.buildcfg}" + +project "Cpp" + location "Examples/Cpp" + kind "ConsoleApp" + language "C++" + + targetdir ("Binaries/" .. outputDir) + objdir ("Intermediate/") + + files + { + "Examples/%{prj.name}/**.h", + "Examples/%{prj.name}/**.cpp", + } + + includedirs + { + "Source" + } + + libdirs + { + "Binaries/%{cfg.buildcfg}" + } + + filter "system:windows" + staticruntime "On" + systemversion "latest" + + links + { + "TribuFu.lib" + } + + filter { "system:windows", "configurations:debug" } + runtime "Debug" + buildoptions "/MDd" + symbols "on" + + filter { "system:windows", "configurations:release" } + runtime "Release" + buildoptions "/MD" + optimize "on" + +project "C" + location "Examples/C" + kind "ConsoleApp" + language "C" + + targetdir ("Binaries/" .. outputDir) + objdir ("Intermediate/") + + files + { + "Examples/%{prj.name}/**.h", + "Examples/%{prj.name}/**.c", + } + + includedirs + { + "Source" + } + + libdirs + { + "Binaries/%{cfg.buildcfg}" + } + + filter "system:windows" + staticruntime "On" + systemversion "latest" + + links + { + "TribuFu.lib" + } + + filter { "system:windows", "configurations:debug" } + runtime "Debug" + buildoptions "/MDd" + symbols "on" + + filter { "system:windows", "configurations:release" } + runtime "Release" + buildoptions "/MD" + optimize "on" + +project "CSharp" + location "Examples/CSharp" + kind "ConsoleApp" + language "C#" + + targetdir ("Binaries/" .. outputDir) + objdir ("Intermediate/") + + files + { + "Examples/%{prj.name}/**.cs", + } + + includedirs + { + "Source" + } + + libdirs + { + "Binaries/%{cfg.buildcfg}" + } + + filter "system:windows" + staticruntime "On" + systemversion "latest" + + defines + { + "WINDOWS_PLATFORM" + } + + filter { "system:windows", "configurations:debug" } + runtime "Debug" + buildoptions "/MDd" + symbols "on" + + filter { "system:windows", "configurations:release" } + runtime "Release" + buildoptions "/MD" + optimize "on"