Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Install build dependencies
run: |
Expand All @@ -40,8 +38,6 @@ jobs:
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Build
run: cargo build --verbose
Expand All @@ -57,8 +53,6 @@ jobs:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Build
run: cargo build --verbose
Expand Down
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,3 @@
**/*.rs.bk
Cargo.lock

# GmSSL submodule build artifacts (the cmake crate builds into OUT_DIR
# inside target/, but manual cmake runs inside the submodule would land here)
gmssl-sys/GmSSL/build/
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

18 changes: 6 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,13 @@

### 快速开始

GmSSL C 库以 **Git 子模块** 的形式包含在本项目中,`cargo build` 会自动通过 CMake 编译 GmSSL,无需手动安装。
GmSSL C 库源码由 `cargo build` 时自动从 GitHub 下载对应发布版 tarball 并用 CMake 编译为静态库,无需手动安装;本地开发可用 `GMSSL_SOURCE_DIR` 指向已有的 GmSSL 源码树。

```bash
# 克隆时初始化子模块(推荐)
git clone --recursive https://github.com/GmSSL/gmssl-rs.git
git clone https://github.com/GmSSL/gmssl-rs.git
cd gmssl-rs

# 如果已克隆但未初始化子模块
git submodule update --init

# 构建(自动编译 GmSSL C 库并链接为静态库)
# 构建(自动下载 GmSSL 源码、编译并链接为静态库)
cargo build

# 运行测试
Expand All @@ -45,7 +41,7 @@ cargo test

### 可选:使用系统预装的 GmSSL

如果你已在系统中安装了 GmSSL(例如通过 `brew install gmssl`),可以设置 `GMSSL_DIR` 环境变量跳过子模块编译:
如果你已在系统中安装了 GmSSL(例如通过 `brew install gmssl`),可以设置 `GMSSL_DIR` 环境变量跳过源码下载与编译:

```bash
export GMSSL_DIR=/usr/local # 或 /opt/homebrew(Apple Silicon Mac)
Expand All @@ -58,7 +54,7 @@ cargo build

```toml
[dependencies]
gmssl-rs = "0.1"
gmssl-rs = "0.2"
```

### SM3 哈希
Expand Down Expand Up @@ -216,11 +212,9 @@ rand_bytes(&mut buf).unwrap();
```
gmssl-rs/
├── Cargo.toml # 工作空间配置
├── .gitmodules # Git 子模块配置(声明对 GmSSL C 库的依赖)
├── gmssl-sys/ # 底层 FFI 绑定(gmssl-rs-sys)
│ ├── Cargo.toml # build-dependencies: cmake
│ ├── build.rs # CMake 自动构建 libgmssl.a
│ ├── GmSSL/ # Git 子模块:GmSSL C 源码(v3.1.1)
│ ├── build.rs # 下载 GmSSL 源码并用 CMake 构建 libgmssl.a
│ └── src/lib.rs # extern "C" 声明与 repr(C) 类型
└── gmssl/ # 安全 Rust 封装(gmssl-rs)
└── src/
Expand Down
2 changes: 1 addition & 1 deletion gmssl-sys/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "gmssl-rs-sys"
version = "0.1.0"
version = "0.2.0"
edition = "2021"
links = "gmssl"
description = "Low-level FFI bindings to the GmSSL cryptographic library"
Expand Down
1 change: 0 additions & 1 deletion gmssl-sys/GmSSL
Submodule GmSSL deleted from d655c0
34 changes: 21 additions & 13 deletions gmssl-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ fn main() {
);
println!("cargo:rustc-link-search=native={}", lib_dir.display());
println!("cargo:rustc-link-lib=gmssl");
emit_platform_link_libs();
println!("cargo:rerun-if-env-changed=GMSSL_DIR");
println!("cargo:rerun-if-changed=build.rs");
return;
Expand Down Expand Up @@ -153,22 +154,29 @@ fn main() {
println!("cargo:include={}", include_dir.display());
}

// macOS: Security.framework needed by rand_apple.c
if env::var("CARGO_CFG_TARGET_OS").unwrap_or_default() == "macos" {
println!("cargo:rustc-link-lib=framework=Security");
}
// Windows: system crypto libs used by GmSSL
if env::var("CARGO_CFG_TARGET_OS").unwrap_or_default() == "windows" {
println!("cargo:rustc-link-lib=advapi32");
println!("cargo:rustc-link-lib=bcrypt");
println!("cargo:rustc-link-lib=ncrypt");
}
emit_platform_link_libs();

println!("cargo:rerun-if-env-changed=GMSSL_DIR");
println!("cargo:rerun-if-env-changed=GMSSL_CMAKE_DEFINES");
println!("cargo:rerun-if-changed=build.rs");
}

/// Emit the OS libraries a GmSSL build may reference — Security.framework
/// for `rand_apple.c` (macOS) and the CryptoAPI libs for `rand_win.c`
/// (Windows). Required both for a library built here and for a prebuilt
/// one supplied via `GMSSL_DIR`; harmless when nothing pulls them in.
fn emit_platform_link_libs() {
match env::var("CARGO_CFG_TARGET_OS").unwrap_or_default().as_str() {
"macos" => println!("cargo:rustc-link-lib=framework=Security"),
"windows" => {
println!("cargo:rustc-link-lib=advapi32");
println!("cargo:rustc-link-lib=bcrypt");
println!("cargo:rustc-link-lib=ncrypt");
}
_ => {}
}
}

/// On Windows MSVC, GmSSL's CMakeLists.txt hardcodes
/// `set(CMAKE_INSTALL_PREFIX "C:/Program Files/GmSSL")` which
/// overrides the value we pass via `-D`. Patch it temporarily
Expand Down Expand Up @@ -254,9 +262,9 @@ fn locate_gmssl_source(_manifest_dir: &PathBuf) -> PathBuf {
return path;
}

// Always use the release tarball by default. The repository still contains
// a historical submodule, but it can drift from the release tag that these
// bindings are generated for.
// Always use the release tarball by default: it matches the release tag
// these bindings are generated for, and it keeps crates.io installs (and
// git-dependency installs) free of submodules.
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
let tarball_dir = out_dir.join("gmssl-src");
let tarball_path = out_dir.join(format!("GmSSL-{}.tar.gz", GMSSL_RELEASE_TAG));
Expand Down
4 changes: 2 additions & 2 deletions gmssl/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "gmssl-rs"
version = "0.1.1"
version = "0.2.0"
edition = "2021"
description = "Safe, idiomatic Rust wrapper for the GmSSL cryptographic library (SM2/SM3/SM4/SM9/ZUC/X.509)"
repository = "https://github.com/GmSSL/gmssl-rs"
Expand All @@ -12,7 +12,7 @@ keywords = ["cryptography", "gmssl", "sm2", "sm3", "sm4"]
categories = ["cryptography", "api-bindings"]

[dependencies]
gmssl-rs-sys = { path = "../gmssl-sys", version = "0.1" }
gmssl-rs-sys = { path = "../gmssl-sys", version = "0.2" }
libc = "0.2"

[dev-dependencies]
Expand Down