Skip to content

Commit a50723d

Browse files
committed
Modernização do projeto: edition 2024, dependências atualizadas e melhorias de código
- Atualizado Rust edition de 2018 para 2024 com resolver 3 - Substituído static mut por AtomicPtr (runtime.rs, encoding.rs) - Atualizado todas as dependências: syn 2.0, bitflags 2.10, fern 0.7, memcache 0.19 - Removida dependência morta colored (build-dep sem build.rs) - Renomeado Args::next() para Args::next_arg() para evitar confusão com Iterator - Corrigido sombreamento do Display trait no AmxString - Adicionadas docs de Safety, correção de precedência, padrões idiomáticos Rust - Substituído Travis CI por GitHub Actions - Adicionado LICENSE (MIT), CHANGELOG.md, README atualizado em português - Removidos docs/ obsoleto, .rustfmt.toml e branches antigas
1 parent 17ecb2f commit a50723d

697 files changed

Lines changed: 324 additions & 15168 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/rust.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Rust
2+
3+
on:
4+
push:
5+
branches: [ "master" ]
6+
pull_request:
7+
branches: [ "master" ]
8+
9+
env:
10+
CARGO_TERM_COLOR: always
11+
12+
jobs:
13+
build:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- name: Install Rust
20+
uses: dtolnay/rust-toolchain@stable
21+
with:
22+
targets: i686-unknown-linux-gnu
23+
24+
- name: Cache cargo registry
25+
uses: actions/cache@v3
26+
with:
27+
path: ~/.cargo/registry
28+
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
29+
30+
- name: Cache cargo index
31+
uses: actions/cache@v3
32+
with:
33+
path: ~/.cargo/git
34+
key: ${{ runner.os }}-cargo-git-${{ hashFiles('**/Cargo.lock') }}
35+
36+
- name: Cache cargo build
37+
uses: actions/cache@v3
38+
with:
39+
path: target
40+
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}
41+
42+
- name: Build
43+
run: cargo build --verbose
44+
45+
- name: Run tests
46+
run: cargo test --verbose
47+
48+
- name: Run clippy
49+
run: cargo clippy --all-targets -- -D warnings

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
/target
2+
/docs
23
**/*.rs.bk
34
Cargo.lock
4-
.idea
5+
.idea
6+
.claude
7+
CLAUDE.md

.rustfmt.toml

Lines changed: 0 additions & 1 deletion
This file was deleted.

.travis.yml

Lines changed: 0 additions & 15 deletions
This file was deleted.

CHANGELOG.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Changelog
2+
3+
## [Unreleased] - NullSablex (fork)
4+
5+
### Modernização
6+
- Atualizado Rust edition de 2018 para **2024**
7+
- Adicionado workspace `resolver = "3"`
8+
- Substituído `static mut` por `AtomicPtr` em `runtime.rs` e `encoding.rs`
9+
- Substituído `#[no_mangle]` por `#[unsafe(no_mangle)]` (exigido pela edition 2024)
10+
- Adicionadas lifetimes explícitas onde a edition 2024 exige (`amx.rs`)
11+
- Substituído `std::mem::transmute` por `f32::to_bits().cast_signed()` em `repr.rs`
12+
13+
### Dependências
14+
- `syn` 0.15 → 2.0, `proc-macro2` 0.4 → 1.0, `quote` 0.6 → 1.0
15+
- `bitflags` 1.0 → 2.10 (com derives obrigatórios)
16+
- `fern` 0.5 → 0.7
17+
- `memcache` 0.12 → 0.19
18+
- Removida dependência morta `colored` (build-dep sem build.rs)
19+
20+
### Otimizações de código
21+
- `.map().flatten()``.filter_map()` no codegen
22+
- `match/Err(_) => ()``if let` em `runtime.rs`
23+
- `unsafe { String::from_utf8_unchecked() }``String::from_utf8_lossy()` em `string.rs`
24+
- `to_string()` que sombreava `Display``convert_to_string()` interno
25+
- Adicionados parênteses de precedência em operação bitshift
26+
- Renomeado `Args::next()``Args::next_arg()` para evitar confusão com `Iterator`
27+
- Removidas lifetimes desnecessárias (`strlen`, `add`)
28+
- Adicionada documentação `# Safety` em `AmxPrimitive` e `AmxString::new`
29+
30+
### Infraestrutura
31+
- Removido `.travis.yml`, adicionado GitHub Actions (`.github/workflows/rust.yml`)
32+
- Removido `.rustfmt.toml` obsoleto (`fn_args_density` descontinuado)
33+
- Removida pasta `docs/` (build antigo de `cargo doc`)
34+
- Adicionado `LICENSE` MIT na raiz
35+
- README reescrito em português
36+
- Adicionado `CHANGELOG.md`
37+
- Removidas branches obsoletas (`potential-fix`, `pre-0.9.0`, `async-amx`)
38+
39+
---
40+
41+
## Histórico original (samp-rs por ZOTTCE e colaboradores)
42+
43+
### 0.9.x (2019)
44+
- Nova API do SDK com `AmxString`, `AmxCell`, `Buffer`
45+
- Macros procedurais `#[native]` e `initialize_plugin!` substituindo `define_native!` e `new_plugin!`
46+
- Suporte a packed strings
47+
- Argumentos raw para natives (`#[native(raw)]`)
48+
- Feature `encoding` com suporte a Windows-1251/1252
49+
- Logger integrado via `fern`
50+
- Suporte a `process_tick`
51+
- Macro `exec_public!` para chamar callbacks Pawn
52+
- Migração para Rust edition 2018
53+
54+
### 0.1.x - 0.8.x (2018)
55+
- Bindings iniciais para a SA-MP SDK (AMX)
56+
- Macros `new_plugin!`, `define_native!`, `natives!`
57+
- Funções AMX: `exec`, `find_native`, `find_public`, `push_string`, `push_array`, `allot`, `release`
58+
- Macros utilitárias: `get_string!`, `set_string!`, `get_array!`, `exec_native!`
59+
- Suporte a `ProcessTick`
60+
- Documentação e exemplos
61+
62+
### Contribuições externas
63+
- Kaperstone: exemplos de código melhorados
64+
- povargek: correção de assinatura `Logprintf_t`
65+
- xakdog: CI (Travis/AppVeyor), correção de chamadas nativas no Windows, doctests
66+
- Southclaws: remoção da dependência `detour`
67+
- Sreyas-Sreelal: correções em `push_string`, packed strings, `amxStrLen`, `amxGetAddr`
68+
- Cheaterman: compatibilidade com GDK

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[workspace]
2+
resolver = "3"
23
members = [
34
"samp-codegen",
45
"samp-sdk",

LICENSE

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
MIT License
2+
3+
Copyright (c) 2019 ZOTTCE (original samp-rs)
4+
Copyright (c) 2026 NullSablex (Rust-SAMP fork)
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.

README.md

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
[![Build](https://github.com/NullSablex/rust-samp/actions/workflows/rust.yml/badge.svg)](https://github.com/NullSablex/rust-samp/actions)
2+
[![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
3+
4+
# Rust-SAMP
5+
6+
Toolkit em Rust para desenvolvimento de plugins de servidor [SA-MP](http://sa-mp.com). Escreva plugins seguros, rápidos e confiáveis usando Rust no lugar de C/C++.
7+
8+
> **Nota:** Este projeto é um fork de [samp-rs](https://github.com/Pycckue-Bnepeg/samp-rs), originalmente criado por [ZOTTCE](https://github.com/ZOTTCE). Foi atualizado com dependências modernas, Rust edition 2024 e práticas de segurança aprimoradas.
9+
10+
## Funcionalidades
11+
12+
- Derive de funções nativas SA-MP com o atributo `#[native]`
13+
- Parsing automático de argumentos do AMX para tipos Rust
14+
- Suporte a encoding de strings (Windows-1251, Windows-1252)
15+
- Logging integrado via `fern` e `log`
16+
- Abstrações seguras sobre a API bruta do AMX
17+
18+
## Estrutura do Projeto
19+
20+
| Crate | Descrição |
21+
|---|---|
22+
| `samp` | Crate principal que une tudo (é o que você precisa) |
23+
| `samp-codegen` | Macros procedurais que geram funções FFI `extern "C"` |
24+
| `samp-sdk` | Tipos e bindings de baixo nível para a máquina virtual AMX |
25+
26+
## Começando
27+
28+
1. Instale o [toolchain Rust](https://rustup.rs). Servidores SA-MP são 32-bit, então você precisa do target `i686`:
29+
```sh
30+
rustup target add i686-unknown-linux-gnu # Linux
31+
rustup target add i686-pc-windows-msvc # Windows
32+
```
33+
34+
2. Adicione ao seu `Cargo.toml`:
35+
```toml
36+
[lib]
37+
crate-type = ["cdylib"]
38+
39+
[dependencies]
40+
samp = { git = "https://github.com/NullSablex/rust-samp.git" }
41+
```
42+
43+
3. Escreva seu plugin:
44+
```rust
45+
use samp::prelude::*;
46+
use samp::{native, initialize_plugin};
47+
48+
struct Plugin;
49+
50+
impl SampPlugin for Plugin {
51+
fn on_load(&mut self) {
52+
println!("Plugin carregado.");
53+
}
54+
}
55+
56+
impl Plugin {
57+
#[native(name = "TestNative")]
58+
fn my_native(&mut self, _amx: &Amx, text: AmxString) -> AmxResult<bool> {
59+
let text = text.to_string();
60+
println!("rust plugin: {}", text);
61+
Ok(true)
62+
}
63+
}
64+
65+
initialize_plugin!(
66+
natives: [Plugin::my_native],
67+
{
68+
let plugin = Plugin;
69+
return plugin;
70+
}
71+
);
72+
```
73+
74+
## Migração de Versões Anteriores
75+
76+
Veja o [guia de migração](migration.md) para atualizar do `samp_sdk` para o `samp`.
77+
78+
## Exemplos
79+
80+
Um exemplo completo de plugin memcache está disponível no diretório [`plugin-example`](plugin-example/).
81+
82+
## Reconhecimentos
83+
84+
Este projeto é baseado no [samp-rs](https://github.com/Pycckue-Bnepeg/samp-rs) por [ZOTTCE](https://github.com/ZOTTCE) e colaboradores. O trabalho original é licenciado sob MIT.
85+
86+
## Licença
87+
88+
MIT

docs/.lock

Whitespace-only changes.

docs/COPYRIGHT.txt

Lines changed: 0 additions & 45 deletions
This file was deleted.

0 commit comments

Comments
 (0)