Skip to content

Commit 97476b0

Browse files
committed
addpkg(tur/hnefatafl-copenhagen): 5.6.1-2
- Unfortunately, it does not work properly. There are multiple severe bugs. I am uploading it so that it easier to save and so that others can help if they know how.
1 parent fdcbe75 commit 97476b0

File tree

5 files changed

+394
-0
lines changed

5 files changed

+394
-0
lines changed

tur/hnefatafl-copenhagen/build.sh

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
TERMUX_PKG_HOMEPAGE=https://hnefatafl.org/
2+
# It's suspected that the discord URL being in the description of packages makes the upstream developer happy
3+
# (speculatively, because it might increase their bug report coverage)
4+
# is something like that acceptable to Termux?
5+
TERMUX_PKG_DESCRIPTION="Copenhagen Hnefatafl client. Discord: https://discord.gg/h56CAHEBXd"
6+
TERMUX_PKG_LICENSE="AGPL-V3"
7+
TERMUX_PKG_MAINTAINER="@termux"
8+
TERMUX_PKG_VERSION="5.6.1-2"
9+
TERMUX_PKG_SRCURL="https://codeberg.org/dcampbell/hnefatafl/archive/v$TERMUX_PKG_VERSION.tar.gz"
10+
TERMUX_PKG_SHA256=ce9f494eea0a3e92360efa96cec6251c1fa7a011864096804d073f8560e15ea0
11+
TERMUX_PKG_DEPENDS="alsa-lib, libc++, hicolor-icon-theme, libxi, libxcursor, libxrandr, hicolor-icon-theme, openssl"
12+
TERMUX_PKG_BUILD_IN_SRC=true
13+
TERMUX_PKG_AUTO_UPDATE=true
14+
TERMUX_PKG_HOSTBUILD=true
15+
16+
_install_ubuntu_packages() {
17+
termux_download_ubuntu_packages "$@"
18+
19+
export HOSTBUILD_ROOTFS="${TERMUX_PKG_HOSTBUILD_DIR}/ubuntu_packages"
20+
21+
find "${HOSTBUILD_ROOTFS}" -type f -name '*.pc' | \
22+
xargs -n 1 sed -i -e "s|/usr|${HOSTBUILD_ROOTFS}/usr|g"
23+
24+
find "${HOSTBUILD_ROOTFS}/usr/lib/x86_64-linux-gnu" -xtype l \
25+
-exec sh -c "ln -snvf /usr/lib/x86_64-linux-gnu/\$(readlink \$1) \$1" sh {} \;
26+
27+
export LD_LIBRARY_PATH="${HOSTBUILD_ROOTFS}/usr/lib/x86_64-linux-gnu"
28+
LD_LIBRARY_PATH+=":${HOSTBUILD_ROOTFS}/usr/lib"
29+
30+
export PKG_CONFIG_LIBDIR="${HOSTBUILD_ROOTFS}/usr/lib/x86_64-linux-gnu/pkgconfig"
31+
PKG_CONFIG_LIBDIR+=":/usr/lib/x86_64-linux-gnu/pkgconfig"
32+
}
33+
34+
termux_step_host_build() {
35+
# build man page
36+
37+
if [[ "$TERMUX_ON_DEVICE_BUILD" == "true" ]]; then
38+
return
39+
fi
40+
41+
_install_ubuntu_packages libasound2-dev
42+
43+
termux_setup_rust
44+
pushd "$TERMUX_PKG_SRCDIR"
45+
rm -f .cargo/config.toml
46+
cargo build \
47+
--jobs "$TERMUX_PKG_MAKE_PROCESSES" \
48+
--release
49+
target/release/hnefatafl-ai --man --username ""
50+
target/release/hnefatafl-client --man
51+
target/release/hnefatafl-server --man
52+
target/release/hnefatafl-server-full --man
53+
target/release/hnefatafl-text-protocol --man
54+
cp hnefatafl-ai.1 "$TERMUX_PKG_HOSTBUILD_DIR"/
55+
cp hnefatafl-server.1 "$TERMUX_PKG_HOSTBUILD_DIR"/
56+
cp hnefatafl-server-full.1 "$TERMUX_PKG_HOSTBUILD_DIR"/
57+
cp hnefatafl-text-protocol.1 "$TERMUX_PKG_HOSTBUILD_DIR"/
58+
cp hnefatafl-client.1 "$TERMUX_PKG_HOSTBUILD_DIR"/
59+
popd
60+
}
61+
62+
termux_step_pre_configure() {
63+
termux_setup_rust
64+
65+
rm -f .cargo/config.toml
66+
67+
: "${CARGO_HOME:=$HOME/.cargo}"
68+
export CARGO_HOME
69+
70+
cargo vendor
71+
find ./vendor \
72+
-mindepth 1 -maxdepth 1 -type d \
73+
! -wholename ./vendor/cpal \
74+
! -wholename ./vendor/smithay-client-toolkit \
75+
! -wholename ./vendor/smithay-client-toolkit-0.19.2 \
76+
! -wholename ./vendor/softbuffer \
77+
! -wholename ./vendor/wayland-cursor \
78+
! -wholename ./vendor/wgpu-hal \
79+
! -wholename ./vendor/winit \
80+
! -wholename ./vendor/x11rb-protocol \
81+
! -wholename ./vendor/xkbcommon-dl \
82+
-exec rm -rf '{}' \;
83+
84+
# currently, there is only one relevant version of "iced winit", but most likely,
85+
# if this winit fork ever changes, the version necessary for hnefatafl-copenhagen
86+
# will be connected to the version of hnefatafl-copenhagen, i.e. older versions of
87+
# hnefatafl-copenhagen will require this commit, but future versions of hnefatafl-copenhagen
88+
# could require a different commit.
89+
local _ICED_WINIT_COMMIT=2e28820207080f4499382df3a4fedb0da81562d3
90+
git clone https://github.com/iced-rs/winit.git vendor/winit-iced
91+
git -C vendor/winit-iced checkout "$_ICED_WINIT_COMMIT"
92+
93+
find vendor/{cpal,smithay-client-toolkit,smithay-client-toolkit-0.19.2,softbuffer,wgpu-hal,winit,winit-iced,x11rb-protocol,xkbcommon-dl} -type f | \
94+
xargs -n 1 sed -i \
95+
-e 's|target_os = "android"|target_os = "disabling_this_because_it_is_for_building_an_apk"|g' \
96+
-e 's|target_os = "linux"|target_os = "android"|g' \
97+
-e "s|libxkbcommon.so.0|libxkbcommon.so|g" \
98+
-e "s|libxkbcommon-x11.so.0|libxkbcommon-x11.so|g" \
99+
-e "s|libxcb.so.1|libxcb.so|g" \
100+
-e "s|/tmp|$TERMUX_PREFIX/tmp|g"
101+
102+
for crate in wayland-cursor softbuffer; do
103+
local patch="$TERMUX_PKG_BUILDER_DIR/$crate-no-shm.diff"
104+
local dir="vendor/$crate"
105+
echo "Applying patch: $patch"
106+
patch -p1 -d "$dir" < "${patch}"
107+
done
108+
109+
local patch="$TERMUX_PKG_BUILDER_DIR/smithay-client-toolkit-0.19.2-no-shm.diff"
110+
local dir="vendor/smithay-client-toolkit-0.19.2"
111+
echo "Applying patch: $patch"
112+
patch -p1 -d "$dir" < "${patch}"
113+
114+
local patch="$TERMUX_PKG_BUILDER_DIR/smithay-client-toolkit-0.20.0-no-shm.diff"
115+
local dir="vendor/smithay-client-toolkit"
116+
echo "Applying patch: $patch"
117+
patch -p1 -d "$dir" < "${patch}"
118+
119+
echo "" >> Cargo.toml
120+
echo '[patch.crates-io]' >> Cargo.toml
121+
for crate in cpal smithay-client-toolkit softbuffer wayland-cursor wgpu-hal winit x11rb-protocol xkbcommon-dl; do
122+
echo "$crate = { path = \"./vendor/$crate\" }" >> Cargo.toml
123+
done
124+
echo "smithay-client-toolkit2 = { package = \"smithay-client-toolkit\", path = \"./vendor/smithay-client-toolkit-0.19.2\" }" >> Cargo.toml
125+
echo "" >> Cargo.toml
126+
echo '[patch."git+https://github.com/iced-rs/winit.git"]' >> Cargo.toml
127+
echo 'winit = { path = "./vendor/winit-iced" }' >> Cargo.toml
128+
}
129+
130+
termux_step_make() {
131+
cargo build \
132+
--jobs "$TERMUX_PKG_MAKE_PROCESSES" \
133+
--target "$CARGO_TARGET_NAME" \
134+
--release
135+
136+
if [[ "$TERMUX_ON_DEVICE_BUILD" == "true" ]]; then
137+
target/"$CARGO_TARGET_NAME"/release/hnefatafl-ai --man --username ""
138+
target/"$CARGO_TARGET_NAME"/release/hnefatafl-client --man
139+
target/"$CARGO_TARGET_NAME"/release/hnefatafl-server --man
140+
target/"$CARGO_TARGET_NAME"/release/hnefatafl-server-full --man
141+
target/"$CARGO_TARGET_NAME"/release/hnefatafl-text-protocol --man
142+
else
143+
cp "$TERMUX_PKG_HOSTBUILD_DIR"/hnefatafl-ai.1 "$TERMUX_PKG_BUILDDIR"/
144+
cp "$TERMUX_PKG_HOSTBUILD_DIR"/hnefatafl-server.1 "$TERMUX_PKG_BUILDDIR"/
145+
cp "$TERMUX_PKG_HOSTBUILD_DIR"/hnefatafl-server-full.1 "$TERMUX_PKG_BUILDDIR"/
146+
cp "$TERMUX_PKG_HOSTBUILD_DIR"/hnefatafl-text-protocol.1 "$TERMUX_PKG_BUILDDIR"/
147+
cp "$TERMUX_PKG_HOSTBUILD_DIR"/hnefatafl-client.1 "$TERMUX_PKG_BUILDDIR"/
148+
fi
149+
}
150+
151+
termux_step_make_install() {
152+
install -Dm755 target/"$CARGO_TARGET_NAME"/release/hnefatafl-ai -t "$TERMUX_PREFIX"/bin
153+
install -Dm755 target/"$CARGO_TARGET_NAME"/release/hnefatafl-client -t "$TERMUX_PREFIX"/bin
154+
install -Dm755 target/"$CARGO_TARGET_NAME"/release/hnefatafl-server -t "$TERMUX_PREFIX"/bin
155+
install -Dm755 target/"$CARGO_TARGET_NAME"/release/hnefatafl-server-full -t "$TERMUX_PREFIX"/bin
156+
install -Dm755 target/"$CARGO_TARGET_NAME"/release/hnefatafl-text-protocol -t "$TERMUX_PREFIX"/bin
157+
install -Dm644 website/src/images/helmet.svg "$TERMUX_PREFIX"/share/icons/hicolor/scalable/apps/org.hnefatafl.hnefatafl_client.svg
158+
install -Dm644 hnefatafl-ai.1 "$TERMUX_PREFIX"/share/man/man1/hnefatafl-ai.1
159+
install -Dm644 hnefatafl-client.1 "$TERMUX_PREFIX"/share/man/man1/hnefatafl-client.1
160+
install -Dm644 hnefatafl-server.1 "$TERMUX_PREFIX"/share/man/man1/hnefatafl-server.1
161+
install -Dm644 hnefatafl-server-full.1 "$TERMUX_PREFIX"/share/man/man1/hnefatafl-server-full.1
162+
install -Dm644 hnefatafl-text-protocol.1 "$TERMUX_PREFIX"/share/man/man1/hnefatafl-text-protocol.1
163+
install -Dm644 packages/hnefatafl-client.desktop "$TERMUX_PREFIX"/share/applications/hnefatafl-client.desktop
164+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
diff --git a/src/shm/raw.rs b/src/shm/raw.rs
2+
index 1a93b8b..8385829 100644
3+
--- a/src/shm/raw.rs
4+
+++ b/src/shm/raw.rs
5+
@@ -5,7 +5,6 @@
6+
7+
use rustix::{
8+
io::Errno,
9+
- shm::{Mode, ShmOFlags},
10+
};
11+
use std::{
12+
fs::File,
13+
@@ -175,49 +174,11 @@ impl RawPool {
14+
Ok(fd) => return Ok(fd),
15+
16+
// Not supported, use fallback.
17+
- Err(Errno::NOSYS) => (),
18+
+ Err(Errno::NOSYS) => return Err(Errno::NOSYS.into()),
19+
20+
Err(err) => return Err(Into::<io::Error>::into(err)),
21+
};
22+
}
23+
-
24+
- let time = SystemTime::now();
25+
- let mut mem_file_handle = format!(
26+
- "/smithay-client-toolkit-{}",
27+
- time.duration_since(UNIX_EPOCH).unwrap().subsec_nanos()
28+
- );
29+
-
30+
- loop {
31+
- let flags = ShmOFlags::CREATE | ShmOFlags::EXCL | ShmOFlags::RDWR;
32+
-
33+
- let mode = Mode::RUSR | Mode::WUSR;
34+
-
35+
- match rustix::shm::shm_open(mem_file_handle.as_str(), flags, mode) {
36+
- Ok(fd) => match rustix::shm::shm_unlink(mem_file_handle.as_str()) {
37+
- Ok(_) => return Ok(fd),
38+
-
39+
- Err(errno) => {
40+
- return Err(errno.into());
41+
- }
42+
- },
43+
-
44+
- Err(Errno::EXIST) => {
45+
- // Change the handle if we happen to be duplicate.
46+
- let time = SystemTime::now();
47+
-
48+
- mem_file_handle = format!(
49+
- "/smithay-client-toolkit-{}",
50+
- time.duration_since(UNIX_EPOCH).unwrap().subsec_nanos()
51+
- );
52+
-
53+
- continue;
54+
- }
55+
-
56+
- Err(Errno::INTR) => continue,
57+
-
58+
- Err(err) => return Err(err.into()),
59+
- }
60+
- }
61+
}
62+
63+
#[cfg(target_os = "android")]
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
diff --git a/src/shm/raw.rs b/src/shm/raw.rs
2+
index 41ae652..686261d 100644
3+
--- a/src/shm/raw.rs
4+
+++ b/src/shm/raw.rs
5+
@@ -5,7 +5,6 @@
6+
7+
use rustix::{
8+
io::Errno,
9+
- shm::{Mode, OFlags},
10+
};
11+
use std::{
12+
fs::File,
13+
@@ -188,49 +187,12 @@ impl RawPool {
14+
Ok(fd) => return Ok(fd),
15+
16+
// Not supported, use fallback.
17+
- Err(Errno::NOSYS) => (),
18+
+ Err(Errno::NOSYS) => return Err(Errno::NOSYS.into()),
19+
20+
Err(err) => return Err(Into::<io::Error>::into(err)),
21+
};
22+
}
23+
24+
- let time = SystemTime::now();
25+
- let mut mem_file_handle = format!(
26+
- "/smithay-client-toolkit-{}",
27+
- time.duration_since(UNIX_EPOCH).unwrap().subsec_nanos()
28+
- );
29+
-
30+
- loop {
31+
- let flags = OFlags::CREATE | OFlags::EXCL | OFlags::RDWR;
32+
-
33+
- let mode = Mode::RUSR | Mode::WUSR;
34+
-
35+
- match rustix::shm::open(mem_file_handle.as_str(), flags, mode) {
36+
- Ok(fd) => match rustix::shm::unlink(mem_file_handle.as_str()) {
37+
- Ok(_) => return Ok(fd),
38+
-
39+
- Err(errno) => {
40+
- return Err(errno.into());
41+
- }
42+
- },
43+
-
44+
- Err(Errno::EXIST) => {
45+
- // Change the handle if we happen to be duplicate.
46+
- let time = SystemTime::now();
47+
-
48+
- mem_file_handle = format!(
49+
- "/smithay-client-toolkit-{}",
50+
- time.duration_since(UNIX_EPOCH).unwrap().subsec_nanos()
51+
- );
52+
-
53+
- continue;
54+
- }
55+
-
56+
- Err(Errno::INTR) => continue,
57+
-
58+
- Err(err) => return Err(err.into()),
59+
- }
60+
- }
61+
}
62+
63+
#[cfg(target_os = "android")]
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
diff --git a/src/backends/x11.rs b/src/backends/x11.rs
2+
index b01fb5f..2a30172 100644
3+
--- a/src/backends/x11.rs
4+
+++ b/src/backends/x11.rs
5+
@@ -14,7 +14,7 @@ use raw_window_handle::{
6+
};
7+
use rustix::{
8+
fd::{AsFd, BorrowedFd, OwnedFd},
9+
- mm, shm as posix_shm,
10+
+ mm,
11+
};
12+
13+
use std::{
14+
@@ -827,37 +827,6 @@ impl<D: ?Sized, W: ?Sized> Drop for X11Impl<D, W> {
15+
16+
/// Create a shared memory identifier.
17+
fn create_shm_id() -> io::Result<OwnedFd> {
18+
- use posix_shm::{Mode, OFlags};
19+
-
20+
- let mut rng = fastrand::Rng::new();
21+
- let mut name = String::with_capacity(23);
22+
-
23+
- // Only try four times; the chances of a collision on this space is astronomically low, so if
24+
- // we miss four times in a row we're probably under attack.
25+
- for i in 0..4 {
26+
- name.clear();
27+
- name.push_str("softbuffer-x11-");
28+
- name.extend(std::iter::repeat_with(|| rng.alphanumeric()).take(7));
29+
-
30+
- // Try to create the shared memory segment.
31+
- match posix_shm::open(
32+
- &name,
33+
- OFlags::RDWR | OFlags::CREATE | OFlags::EXCL,
34+
- Mode::RWXU,
35+
- ) {
36+
- Ok(id) => {
37+
- posix_shm::unlink(&name).ok();
38+
- return Ok(id);
39+
- }
40+
-
41+
- Err(rustix::io::Errno::EXIST) => {
42+
- tracing::warn!("x11: SHM ID collision at {} on try number {}", name, i);
43+
- }
44+
-
45+
- Err(e) => return Err(e.into()),
46+
- };
47+
- }
48+
-
49+
Err(io::Error::new(
50+
io::ErrorKind::Other,
51+
"failed to generate a non-existent SHM name",
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
diff --git a/src/lib.rs b/src/lib.rs
2+
index 9993801..ea64a47 100644
3+
--- a/src/lib.rs
4+
+++ b/src/lib.rs
5+
@@ -59,7 +59,6 @@ use rustix::fs::Mode;
6+
#[cfg(any(target_os = "linux", target_os = "android"))]
7+
use rustix::fs::{memfd_create, MemfdFlags};
8+
use rustix::io::Errno;
9+
-use rustix::shm;
10+
#[cfg(any(target_os = "linux", target_os = "android"))]
11+
use std::ffi::CStr;
12+
13+
@@ -445,39 +444,10 @@ fn create_shm_fd() -> IoResult<OwnedFd> {
14+
) {
15+
Ok(fd) => return Ok(fd),
16+
Err(Errno::INTR) => continue,
17+
- Err(Errno::NOSYS) => break,
18+
+ Err(Errno::NOSYS) => return Err(Errno::NOSYS.into()),
19+
Err(errno) => return Err(errno.into()),
20+
}
21+
}
22+
-
23+
- // Fallback to using shm_open.
24+
- let sys_time = SystemTime::now();
25+
- let mut mem_file_handle = format!(
26+
- "/wayland-cursor-rs-{}",
27+
- sys_time.duration_since(UNIX_EPOCH).unwrap().subsec_nanos()
28+
- );
29+
- loop {
30+
- match shm::open(
31+
- mem_file_handle.as_str(),
32+
- shm::OFlags::CREATE | shm::OFlags::EXCL | shm::OFlags::RDWR,
33+
- Mode::RUSR | Mode::WUSR,
34+
- ) {
35+
- Ok(fd) => match shm::unlink(mem_file_handle.as_str()) {
36+
- Ok(_) => return Ok(fd),
37+
- Err(errno) => return Err(IoError::from(errno)),
38+
- },
39+
- Err(Errno::EXIST) => {
40+
- // If a file with that handle exists then change the handle
41+
- mem_file_handle = format!(
42+
- "/wayland-cursor-rs-{}",
43+
- sys_time.duration_since(UNIX_EPOCH).unwrap().subsec_nanos()
44+
- );
45+
- continue;
46+
- }
47+
- Err(Errno::INTR) => continue,
48+
- Err(errno) => return Err(IoError::from(errno)),
49+
- }
50+
- }
51+
}
52+
53+
struct IgnoreObjectData;

0 commit comments

Comments
 (0)