Add Premake and FFI Bindings

This commit is contained in:
GuilhermeWerner
2021-02-24 09:13:18 -03:00
parent 36df99c7e0
commit 74532a9ace
14 changed files with 399 additions and 0 deletions

113
Config/Bindings.toml Normal file
View File

@ -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 = []

12
Examples/C/Hello.c Normal file
View File

@ -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());
}

24
Examples/CSharp/Hello.cs Normal file
View File

@ -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());
}
}
}

14
Examples/Cpp/Hello.cpp Normal file
View File

@ -0,0 +1,14 @@
// Copyright (c) TribuFu. All Rights Reserved
#include <iostream>
#include "TribuFu.h"
using namespace std;
extern int32_t Hello();
int main()
{
cout << "TribuFu SDK = " << (int)TribuFu::Hello() << "\n";
}

2
GenerateProjectFiles.bat Normal file
View File

@ -0,0 +1,2 @@
cbindgen --config .\Config\Bindings.toml --crate TribuFu --output Source\Header.h
call .\Vendor\Premake\Windows\premake5.exe vs2019

View File

@ -0,0 +1,4 @@
#!/bin/zsh
cbindgen --config ./Config/Bindings.toml --crate TribuFu --output Source/Header.h
sudo ./Vendor/Premake/Mac/premake5 xcode4

4
GenerateProjectFiles.sh Normal file
View File

@ -0,0 +1,4 @@
#!/bin/bash
cbindgen --config ./Config/Bindings.toml --crate TribuFu --output Source/Header.h
sudo ./Vendor/Premake/Linux/premake5 gmake2

61
Source/TribuFu.h Normal file
View File

@ -0,0 +1,61 @@
// Copyright (c) TribuFu. All Rights Reserved
#pragma once
#include <stdarg.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#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

27
Vendor/Premake/LICENSE.txt vendored Normal file
View File

@ -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.

BIN
Vendor/Premake/Linux/premake5 vendored Normal file

Binary file not shown.

BIN
Vendor/Premake/Mac/premake5 vendored Normal file

Binary file not shown.

BIN
Vendor/Premake/Windows/premake5.exe vendored Normal file

Binary file not shown.

BIN
Vendor/rcedit.exe vendored Normal file

Binary file not shown.

138
premake5.lua Normal file
View File

@ -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"