initial version

This commit is contained in:
sijie.sun
2025-01-10 23:03:37 +08:00
commit 519386124c
10 changed files with 125 additions and 0 deletions
+32
View File
@@ -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/git-actions@v0.0.3
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
View File
@@ -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
View File
@@ -0,0 +1,3 @@
[submodule "kcp"]
path = kcp
url = https://github.com/skywind3000/kcp
+16
View File
@@ -0,0 +1,16 @@
[package]
name = "kcp-sys"
version = "0.1.0"
edition = "2021"
authors = ["sunsijie@buaa.edu.cn"]
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
View File
@@ -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
View File
@@ -0,0 +1,3 @@
# kcp-sys
Safe bindings to the [kcp](https://github.com/skywind3000/kcp) transport protocol library.
+33
View File
@@ -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!");
}
Submodule
+1
Submodule kcp added at 7f9805887b
+5
View File
@@ -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
View File
@@ -0,0 +1 @@
#include "kcp/ikcp.h"