Skip to content

Commit c424785

Browse files
committed
patch getrandom 0.3.x
Signed-off-by: sbwml <admin@cooluc.com>
1 parent c131dd4 commit c424785

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

.github/workflows/build-release.yml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,14 @@ jobs:
4444
shadowsocks_version="$(git describe --tags `git rev-list --tags --max-count=1`)"
4545
echo shadowsocks_version="$shadowsocks_version" >> "$GITHUB_ENV"
4646
git checkout $(git describe --tags `git rev-list --tags --max-count=1`)
47-
# moka
48-
if [ "$shadowsocks_version" = "v1.22.0" ]; then
49-
echo '[patch.crates-io]' >> Cargo.toml
50-
echo 'moka = { git = "https://github.com/moka-rs/moka.git", branch = "main" }' >> Cargo.toml
51-
fi
47+
# getrandom local
48+
echo '[patch.crates-io]' >> Cargo.toml
49+
echo 'getrandom = { path = "../getrandom", version = "0.3" }' >> Cargo.toml
50+
cd ..
51+
# patch getrandom
52+
git clone https://github.com/rust-random/getrandom -b v$(grep -oP 'getrandom \d+\.3.\d+' shadowsocks-rust/Cargo.lock | head -1 | awk '{print $2}')
53+
cd getrandom
54+
patch -p1 < ../patches/getrandom-0.3-musl.patch
5255
cd ..
5356
[ "${{ matrix.target }}" = "mips-unknown-linux-musl" ] && target=mips || target=mipsel
5457
export $(echo "CARGO_TARGET_$(echo "$target" | tr '[:lower:]' '[:upper:]')_UNKNOWN_LINUX_MUSL_LINKER"="$target-openwrt-linux-musl-gcc")

patches/getrandom-0.3-musl.patch

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--- a/src/backends/linux_android_with_fallback.rs
2+
+++ b/src/backends/linux_android_with_fallback.rs
3+
@@ -31,8 +31,11 @@ fn init() -> NonNull<c_void> {
4+
};
5+
#[cfg(target_env = "musl")]
6+
let raw_ptr = {
7+
- let fptr: GetRandomFn = libc::getrandom;
8+
- unsafe { transmute::<GetRandomFn, *mut c_void>(fptr) }
9+
+ // Define the getrandom function for musl targets
10+
+ extern "C" {
11+
+ fn getrandom(buf: *mut libc::c_void, buflen: libc::size_t, flags: libc::c_uint) -> libc::ssize_t;
12+
+ }
13+
+ unsafe { transmute::<unsafe extern "C" fn(*mut libc::c_void, libc::size_t, libc::c_uint) -> libc::ssize_t, *mut c_void>(getrandom) }
14+
};
15+
16+
let res_ptr = match NonNull::new(raw_ptr) {

0 commit comments

Comments
 (0)