Skip to content

Commit 3bb13b1

Browse files
author
shijiashuai
committed
提交go和rust版本的gzip的实现
0 parents  commit 3bb13b1

22 files changed

+1519
-0
lines changed

.editorconfig

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
insert_final_newline = true
7+
trim_trailing_whitespace = true
8+
indent_style = space
9+
indent_size = 2
10+
11+
[*.go]
12+
indent_style = tab
13+
indent_size = 4
14+
15+
[*.rs]
16+
indent_style = space
17+
indent_size = 4
18+
19+
[Makefile]
20+
indent_style = tab

.gitattributes

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
* text=auto eol=lf
2+
3+
# Archives
4+
*.gz binary
5+
*.zip binary
6+
*.tar binary
7+
*.tgz binary
8+
*.7z binary
9+
10+
# Binaries & libs
11+
*.exe binary
12+
*.dll binary
13+
*.so binary
14+
*.dylib binary
15+
*.a binary
16+
*.o binary
17+
*.rlib binary
18+
*.pdb binary
19+
*.wasm binary

.github/workflows/ci.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: ["**"]
6+
pull_request:
7+
8+
jobs:
9+
go:
10+
name: Go build & vet
11+
runs-on: ubuntu-latest
12+
defaults:
13+
run:
14+
working-directory: go
15+
steps:
16+
- uses: actions/checkout@v4
17+
- uses: actions/setup-go@v5
18+
with:
19+
go-version: stable
20+
cache: true
21+
- name: Build
22+
run: mkdir -p bin && go build -v -o bin/gzip-go ./cmd/gzip-go
23+
- name: Vet
24+
run: go vet ./...
25+
26+
rust:
27+
name: Rust build
28+
runs-on: ubuntu-latest
29+
defaults:
30+
run:
31+
working-directory: rust
32+
steps:
33+
- uses: actions/checkout@v4
34+
- uses: dtolnay/rust-toolchain@stable
35+
- name: Build
36+
run: cargo build --release --locked

.github/workflows/release.yml

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
permissions:
9+
contents: write
10+
11+
jobs:
12+
go-build:
13+
name: Go Release Artifacts
14+
runs-on: ${{ matrix.os }}
15+
strategy:
16+
fail-fast: false
17+
matrix:
18+
os: [ubuntu-latest, macos-latest, windows-latest]
19+
defaults:
20+
run:
21+
working-directory: go
22+
steps:
23+
- uses: actions/checkout@v4
24+
- uses: actions/setup-go@v5
25+
with:
26+
go-version: stable
27+
cache: true
28+
29+
- name: Build (native)
30+
run: go build ./cmd/gzip-go
31+
32+
- name: Package (Linux/macOS)
33+
if: runner.os != 'Windows'
34+
shell: bash
35+
run: |
36+
set -euo pipefail
37+
VERSION="${GITHUB_REF_NAME}"
38+
GOOS=$(go env GOOS)
39+
GOARCH=$(go env GOARCH)
40+
DIST="${GITHUB_WORKSPACE}/dist"
41+
mkdir -p "$DIST"
42+
BIN="gzip-go"
43+
TAR="${DIST}/gzip-go_${VERSION}_${GOOS}_${GOARCH}.tar.gz"
44+
tar -C . -czf "$TAR" "$BIN"
45+
46+
- name: Package (Windows)
47+
if: runner.os == 'Windows'
48+
shell: pwsh
49+
run: |
50+
$ErrorActionPreference = "Stop"
51+
$version = "$env:GITHUB_REF_NAME"
52+
$goos = & go env GOOS
53+
$goarch = & go env GOARCH
54+
$dist = Join-Path $env:GITHUB_WORKSPACE "dist"
55+
New-Item -ItemType Directory -Force -Path $dist | Out-Null
56+
$bin = "gzip-go.exe"
57+
$zip = Join-Path $dist ("gzip-go_{0}_{1}_{2}.zip" -f $version, $goos, $goarch)
58+
Compress-Archive -Path $bin -DestinationPath $zip -Force
59+
60+
- name: Upload artifact
61+
uses: actions/upload-artifact@v4
62+
with:
63+
name: go-${{ runner.os }}
64+
path: ${{ github.workspace }}/dist/*
65+
66+
rust-build:
67+
name: Rust Release Artifacts
68+
runs-on: ${{ matrix.os }}
69+
strategy:
70+
fail-fast: false
71+
matrix:
72+
os: [ubuntu-latest, macos-latest, windows-latest]
73+
defaults:
74+
run:
75+
working-directory: rust
76+
steps:
77+
- uses: actions/checkout@v4
78+
- uses: dtolnay/rust-toolchain@stable
79+
80+
- name: Build (native)
81+
run: cargo build --release --locked
82+
83+
- name: Package (Linux/macOS)
84+
if: runner.os != 'Windows'
85+
shell: bash
86+
run: |
87+
set -euo pipefail
88+
VERSION="${GITHUB_REF_NAME}"
89+
DIST="${GITHUB_WORKSPACE}/dist"
90+
mkdir -p "$DIST"
91+
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
92+
ARCH=$(uname -m)
93+
case "$ARCH" in x86_64) ARCH=amd64 ;; aarch64) ARCH=arm64 ;; arm64) ARCH=arm64 ;; esac
94+
TAR="${DIST}/rgzip_${VERSION}_${OS}_${ARCH}.tar.gz"
95+
tar -C target/release -czf "$TAR" rgzip
96+
97+
- name: Package (Windows)
98+
if: runner.os == 'Windows'
99+
shell: pwsh
100+
run: |
101+
$ErrorActionPreference = "Stop"
102+
$version = "$env:GITHUB_REF_NAME"
103+
$os = "windows"
104+
$arch = "amd64"
105+
$dist = Join-Path $env:GITHUB_WORKSPACE "dist"
106+
New-Item -ItemType Directory -Force -Path $dist | Out-Null
107+
$exe = "target/release/rgzip.exe"
108+
$zip = Join-Path $dist ("rgzip_{0}_{1}_{2}.zip" -f $version, $os, $arch)
109+
Compress-Archive -Path $exe -DestinationPath $zip -Force
110+
111+
- name: Upload artifact
112+
uses: actions/upload-artifact@v4
113+
with:
114+
name: rust-${{ runner.os }}
115+
path: ${{ github.workspace }}/dist/*
116+
117+
publish:
118+
name: Publish GitHub Release
119+
runs-on: ubuntu-latest
120+
needs: [go-build, rust-build]
121+
steps:
122+
- name: Download all artifacts
123+
uses: actions/download-artifact@v4
124+
with:
125+
path: dist
126+
merge-multiple: true
127+
128+
- name: Generate SHA256SUMS
129+
run: |
130+
set -euo pipefail
131+
cd dist
132+
shopt -s nullglob
133+
files=( *.zip *.tar.gz )
134+
if [ ${#files[@]} -gt 0 ]; then
135+
sha256sum "${files[@]}" > SHA256SUMS
136+
else
137+
echo "No artifacts to checksum" >&2
138+
fi
139+
140+
- name: Create GitHub Release and upload assets
141+
uses: softprops/action-gh-release@v2
142+
with:
143+
tag_name: ${{ github.ref_name }}
144+
name: ${{ github.ref_name }}
145+
draft: false
146+
prerelease: ${{ contains(github.ref_name, '-') }}
147+
files: |
148+
dist/*.zip
149+
dist/*.tar.gz
150+
dist/SHA256SUMS

.gitignore

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# OS / Editor
2+
.DS_Store
3+
Thumbs.db
4+
.vscode/
5+
.idea/
6+
*.swp
7+
*.swo
8+
*.tmp
9+
*.log
10+
11+
# Go outputs
12+
/go/bin/
13+
14+
# Rust outputs
15+
/rust/target/
16+
17+
# Common binaries
18+
**/*.exe
19+
**/*.pdb
20+
**/*.dll
21+
**/*.so
22+
**/*.dylib
23+
**/*.a
24+
**/*.o

README.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# gzip
2+
3+
多语言(Go 与 Rust)实现的极简 gzip 命令行工具集合,遵循 KISS 原则:简单、可维护、易分发,默认聚焦 Linux 使用场景。
4+
5+
## 子项目
6+
- **Go 版**`go/`,可执行文件名为 `gzip-go`,入口位于 `go/cmd/gzip-go/main.go`
7+
- 详细说明见 `go/README.md`
8+
- **Rust 版**`rust/`,可执行文件名为 `rgzip`,核心逻辑在 `rust/src/lib.rs`
9+
- 详细说明见 `rust/README.md`
10+
11+
## 目录结构
12+
```text
13+
./
14+
├── go/
15+
│ ├── cmd/gzip-go/main.go
16+
│ ├── go.mod
17+
│ ├── Makefile
18+
│ ├── README.md
19+
│ └── changelog/
20+
├── rust/
21+
│ ├── Cargo.toml
22+
│ ├── README.md
23+
│ ├── src/{main.rs, lib.rs}
24+
│ └── changelog/
25+
├── .gitignore
26+
├── .gitattributes
27+
├── .editorconfig
28+
└── changelog/
29+
```
30+
31+
## 快速开始
32+
- **构建 Go 版**
33+
```bash
34+
cd go
35+
make build # 生成 go/bin/gzip-go
36+
#
37+
go build -o bin/gzip-go ./cmd/gzip-go
38+
```
39+
- **构建 Rust 版**
40+
```bash
41+
cd rust
42+
cargo build --release # 生成 target/release/rgzip
43+
```
44+
45+
## 使用
46+
- 参见子项目文档:`go/README.md``rust/README.md`
47+
48+
## 开源许可
49+
- Rust 子项目当前声明:`MIT OR Apache-2.0`
50+
- Go 子项目 README 提到 `MIT`(可调整)。
51+
- 请确认仓库根级许可证偏好(`MIT``Apache-2.0`、或双许可证 `MIT OR Apache-2.0`),确认后将添加 `LICENSE` 文件并在各子项目中对齐。
52+
53+
## 贡献
54+
- 欢迎 PR。请遵循:
55+
- 保持 KISS 原则,尽量减少依赖与复杂度。
56+
- 每次修改请在对应子项目的 `changelog/` 或仓库根级 `changelog/` 新增记录。
57+
- 统一代码风格:见 `.editorconfig`;换行符 LF,文本自动归一见 `.gitattributes`
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# 2025-10-20 修复 CI 中 Go 构建步骤
2+
3+
## 变更
4+
- 更新:`.github/workflows/ci.yml`
5+
- 在执行 `go build -o bin/gzip-go` 前新增 `mkdir -p bin`,避免 `bin/` 不存在导致构建失败。
6+
7+
## 影响
8+
- 仅影响 CI 行为,本地构建流程不变。

changelog/2025-10-20-ci-release.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# 2025-10-20 新增 CI 与发布工作流
2+
3+
## 变更
4+
- 新增:`.github/workflows/ci.yml`
5+
- 触发:push / pull_request
6+
- Go(`go/`):`go build` + `go vet`
7+
- Rust(`rust/`):`cargo build --release --locked`
8+
- 新增:`.github/workflows/release.yml`
9+
- 触发:push tag `v*`
10+
- 矩阵:`ubuntu-latest` / `macos-latest` / `windows-latest`
11+
- Go 打包:`gzip-go_${tag}_${GOOS}_${GOARCH}.tar.gz`(Windows 为 zip)
12+
- Rust 打包:`rgzip_${tag}_${os}_${arch}.tar.gz`(Windows 为 zip)
13+
- 生成 `SHA256SUMS` 并附加到 GitHub Release
14+
15+
## 使用说明
16+
- 创建并推送标签以触发发布:
17+
```bash
18+
git tag v0.1.0
19+
git push origin v0.1.0
20+
```
21+
- 工作流需要默认 `GITHUB_TOKEN`(已自动提供),无需额外密钥配置。
22+
23+
## 备注
24+
- 当前为“原生架构”构建(与各运行器一致)。如需额外架构(如 Linux/arm64),后续可扩展交叉编译矩阵。
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# 2025-10-20 标准化仓库结构
2+
3+
## 变更
4+
- 新增:`/.gitignore`
5+
- 忽略系统与编辑器文件(`.DS_Store``.idea/``.vscode/` 等)
6+
- 忽略 Go 产物:`/go/bin/`
7+
- 忽略 Rust 产物:`/rust/target/`
8+
- 忽略常见二进制与库文件(`*.exe``*.dll``*.so``*.a``*.o` 等)
9+
- 新增:`/.gitattributes`
10+
- 强制文本 `eol=lf`
11+
- 将归档/二进制(`*.gz``*.zip``*.tar``*.rlib` 等)标记为 `binary`
12+
- 新增:`/.editorconfig`
13+
- 全局 UTF-8、LF、去除行尾空白、末行换行
14+
- `*.go` 使用 Tab、宽度 4;`*.rs` 使用空格、宽度 4;`Makefile` 使用 Tab
15+
- 新增:`/README.md`
16+
- 仓库总览:`go/``rust/` 子项目简介与指引
17+
- 统一贡献建议与后续许可对齐提醒
18+
- 新增:`/changelog/2025-10-20-standardize.md`(本文件)
19+
20+
## 说明
21+
- 未改动 `go/README.md``rust/README.md` 的既有内容,待确认许可证策略后再对齐文案。
22+
- Rust 子项目当前 `Cargo.toml` 采用 `MIT OR Apache-2.0`;建议根级确定后与 Go、Rust 一并对齐。
23+
24+
## 后续建议
25+
- 选择许可证(`MIT``Apache-2.0` 或双许可证),在根级添加 `LICENSE`,并同步更新子项目文档与元数据。
26+
- (可选)添加社区文件:`CONTRIBUTING.md``CODE_OF_CONDUCT.md``.github/ISSUE_TEMPLATE``PULL_REQUEST_TEMPLATE.md`

go/Makefile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
.PHONY: build build-linux install clean fmt
2+
3+
BIN_DIR := bin
4+
5+
build:
6+
mkdir -p $(BIN_DIR)
7+
go build -o $(BIN_DIR)/gzip-go ./cmd/gzip-go
8+
9+
# Cross-compile for Linux amd64 (from any host)
10+
build-linux:
11+
mkdir -p $(BIN_DIR)
12+
GOOS=linux GOARCH=amd64 go build -o $(BIN_DIR)/gzip-go ./cmd/gzip-go
13+
14+
install: build
15+
install -m 0755 $(BIN_DIR)/gzip-go /usr/local/bin/gzip-go
16+
17+
clean:
18+
rm -rf $(BIN_DIR)
19+
20+
fmt:
21+
go fmt ./...

0 commit comments

Comments
 (0)