Skip to content

Commit

Permalink
initial version
Browse files Browse the repository at this point in the history
  • Loading branch information
KKRainbow committed Jan 10, 2025
0 parents commit 5193861
Show file tree
Hide file tree
Showing 10 changed files with 125 additions and 0 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Rust

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

env:
CARGO_TERM_COLOR: always

jobs:
build:

runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@master
- name: Checkout submodules
uses: srt32/[email protected]
with:
args: git submodule update --init --recursive
- name: Set up Clang
uses: egor-tensin/setup-clang@v1
with:
version: latest
platform: x64
- name: Build
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Generated by Cargo
# will have compiled files and executables
/target/

# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Cargo.lock

# These are backup files generated by rustfmt
**/*.rs.bk
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "kcp"]
path = kcp
url = https://github.com/skywind3000/kcp
16 changes: 16 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "kcp-sys"
version = "0.1.0"
edition = "2021"
authors = ["[email protected]"]
description = "Safe bindings for KCP transport protocol"
repository = "https://github.com/EasyTier/kcp-sys"
readme = "README.md"
license = "MIT"
keywords = ["kcp", "bindings"]

[dependencies]

[build-dependencies]
bindgen = "0.71.1"
cc = "1.2.7"
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 b23r0

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.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# kcp-sys

Safe bindings to the [kcp](https://github.com/skywind3000/kcp) transport protocol library.
33 changes: 33 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use std::env;
use std::path::{Path, PathBuf};

fn main() {
println!("cargo:rustc-link-lib=kcp");
let dir = env::var("CARGO_MANIFEST_DIR").unwrap();
let fulldir = Path::new(&dir).join("kcp");

let mut config = cc::Build::new();
config.include(fulldir.clone());
config.file(fulldir.join("ikcp.c"));
config.opt_level(3);
config.warnings(false);
config.compile("libkcp.a");
println!("cargo:rustc-link-search=native={}", fulldir.display());

println!("cargo:rerun-if-changed=kcp/ikcp.h");
println!("cargo:rerun-if-changed=kcp/ikcp.c");
println!("cargo:rerun-if-changed=wrapper.h");

let bindings = bindgen::Builder::default()
.header("wrapper.h")
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
.allowlist_function("ikcp_.*")
.opaque_type("ikcpcb")
.generate()
.expect("Unable to generate bindings");

let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
bindings
.write_to_file(out_path.join("bindings.rs"))
.expect("Couldn't write bindings!");
}
1 change: 1 addition & 0 deletions kcp
Submodule kcp added at 7f9805
5 changes: 5 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#![allow(non_upper_case_globals)]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]

include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
1 change: 1 addition & 0 deletions wrapper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "kcp/ikcp.h"

0 comments on commit 5193861

Please sign in to comment.