Merge commit '3105cc20ef3173b87fdc1688962ed6318a1fd039'

This commit is contained in:
Green Sky
2025-03-12 19:16:50 +01:00
130 changed files with 3604 additions and 1776 deletions

View File

@ -0,0 +1,102 @@
#!/bin/bash
set -eu
if [ -n "${CI-}" ]; then
sudo apt-get install -y --no-install-recommends ninja-build yasm
fi
# Set up environment
NDK=$ANDROID_NDK_HOME
ABI=${1:-"armeabi-v7a"}
case $ABI in
armeabi-v7a)
TARGET=armv7a-linux-androideabi
NDK_API=21
ANDROID_VPX_ABI=armv7-android-gcc
;;
arm64-v8a)
TARGET=aarch64-linux-android
NDK_API=21
ANDROID_VPX_ABI=arm64-android-gcc
;;
x86)
TARGET=i686-linux-android
NDK_API=21
ANDROID_VPX_ABI=x86-android-gcc
;;
x86_64)
TARGET=x86_64-linux-android
NDK_API=21
ANDROID_VPX_ABI=x86_64-android-gcc
;;
*)
exit 1
;;
esac
PREFIX="$PWD/deps-prefix-android-$ABI"
TOOLCHAIN="$NDK/toolchains/llvm/prebuilt/linux-x86_64"
SYSROOT="$TOOLCHAIN/sysroot"
export CC="$TOOLCHAIN/bin/$TARGET$NDK_API-clang"
export CXX="$TOOLCHAIN/bin/$TARGET$NDK_API-clang++"
export LDFLAGS=-static-libstdc++
export PKG_CONFIG_PATH="$PREFIX/lib/pkgconfig"
# Build libsodium
if [ ! -f "$PREFIX/lib/libsodium.a" ]; then
tar zxf <(wget -O- https://github.com/jedisct1/libsodium/releases/download/1.0.20-RELEASE/libsodium-1.0.20.tar.gz)
pushd libsodium-1.0.20
./configure --prefix="$PREFIX" --host="$TARGET" --with-sysroot="$SYSROOT" --disable-shared --disable-pie
make -j"$(nproc)" install
popd
rm -rf libsodium-1.0.20
fi
# Build opus
if [ ! -f "$PREFIX/lib/libopus.a" ]; then
tar zxf <(wget -O- https://github.com/xiph/opus/releases/download/v1.5.2/opus-1.5.2.tar.gz)
pushd opus-1.5.2
CFLAGS="-fPIC" ./configure --prefix="$PREFIX" --host="$TARGET" --with-sysroot="$SYSROOT" --disable-shared
make "-j$(nproc)"
make install
popd
rm -rf opus-1.5.2
fi
# Build libvpx
if [ ! -f "$PREFIX/lib/libvpx.a" ]; then
tar zxf <(wget -O- https://github.com/webmproject/libvpx/archive/refs/tags/v1.15.0.tar.gz)
pushd libvpx-1.15.0
./configure --prefix="$PREFIX" --libc="$SYSROOT" --target="$ANDROID_VPX_ABI" --disable-examples --disable-unit-tests --enable-pic ||
(cat config.log && exit 1)
sed -i -e "s!^AS=as!AS=$CC -c!" ./*.mk
sed -i -e "s!^STRIP=strip!STRIP=$TOOLCHAIN/bin/llvm-strip!" ./*.mk
make "-j$(nproc)"
make install
popd
rm -rf libvpx-1.15.0
fi
# Build c-toxcore
rm -rf _build
cmake -B _build -G Ninja \
-DANDROID_ABI="$ABI" \
-DCMAKE_TOOLCHAIN_FILE="$NDK/build/cmake/android.toolchain.cmake" \
-DCMAKE_INSTALL_PREFIX="$PWD/toxcore-android-$ABI" \
-DCMAKE_PREFIX_PATH="$PREFIX" \
-DENABLE_STATIC=OFF \
-DENABLE_SHARED=ON \
-DMUST_BUILD_TOXAV=ON \
-DDHT_BOOTSTRAP=OFF \
-DBOOTSTRAP_DAEMON=OFF \
-DUNITTEST=OFF \
-DSTRICT_ABI=ON \
-DMIN_LOGGER_LEVEL=TRACE \
-DEXPERIMENTAL_API=ON
cmake --build _build
cmake --install _build

View File

@ -0,0 +1,5 @@
/Tox.xcframework
/toxcore-ios*
/toxcore-iphonesimulator*
/toxcore-macos*
/smoke-test.c

View File

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>Tox</string>
<key>CFBundleName</key>
<string>Tox</string>
<key>CFBundleIconFile</key>
<string></string>
<key>CFBundleIdentifier</key>
<string>chat.tox.toxcore</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>0.2.20</string>
<key>CFBundleShortVersionString</key>
<string>0.2.20</string>
<key>CFBundleGetInfoString</key>
<string>Tox Framework</string>
</dict>
</plist>

View File

@ -0,0 +1 @@
../../../LICENSE

View File

@ -0,0 +1,29 @@
#!/bin/bash
# Download the nightly builds of Tox for iOS, iPhone simulator, and macOS.
set -eux -o pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
for arch in arm64 armv7 armv7s; do
if [ ! -d "toxcore-ios-$arch" ]; then
tar -zxf \
<(curl -L "https://github.com/TokTok/c-toxcore/releases/download/nightly/toxcore-nightly-ios-$arch.tar.gz")
fi
done
for arch in arm64 x86_64; do
if [ ! -d "toxcore-iphonesimulator-$arch" ]; then
tar -zxf \
<(curl -L "https://github.com/TokTok/c-toxcore/releases/download/nightly/toxcore-nightly-iphonesimulator-$arch.tar.gz")
fi
done
for arch in arm64 x86_64; do
if [ ! -d "toxcore-macos-$arch" ]; then
tar -zxf \
<(curl -L "https://github.com/TokTok/c-toxcore/releases/download/nightly/toxcore-nightly-macos-$arch.tar.gz")
fi
done

View File

@ -0,0 +1,71 @@
#!/bin/bash
# Make a Tox.xcframework for iOS, iPhone simulator, and macOS from the nightly builds.
#
# Run download-nightly.sh before running this script if you run it locally.
set -eux -o pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
# Make a Tox.framework for iOS.
rm -rf toxcore-ios/Tox.framework
mkdir -p toxcore-ios/Tox.framework
cp Info.plist toxcore-ios/Tox.framework
cp -r toxcore-ios-arm64/include/tox toxcore-ios/Tox.framework/Headers
lipo -create -output toxcore-ios/Tox.framework/Tox \
toxcore-ios-arm64/lib/libtoxcore.dylib \
toxcore-ios-armv7/lib/libtoxcore.dylib \
toxcore-ios-armv7s/lib/libtoxcore.dylib
install_name_tool -id @rpath/Tox.framework/Tox toxcore-ios/Tox.framework/Tox
# Make a Tox.framework for iPhone simulator.
rm -rf toxcore-iphonesimulator/Tox.framework
mkdir -p toxcore-iphonesimulator/Tox.framework
cp Info.plist toxcore-iphonesimulator/Tox.framework
cp -r toxcore-iphonesimulator-arm64/include/tox toxcore-iphonesimulator/Tox.framework/Headers
lipo -create -output toxcore-iphonesimulator/Tox.framework/Tox \
toxcore-iphonesimulator-arm64/lib/libtoxcore.dylib \
toxcore-iphonesimulator-x86_64/lib/libtoxcore.dylib
install_name_tool -id @rpath/Tox.framework/Tox toxcore-iphonesimulator/Tox.framework/Tox
# Make a Tox.framework for macOS.
rm -rf toxcore-macos/Tox.framework
mkdir -p toxcore-macos/Tox.framework
cp Info.plist toxcore-macos/Tox.framework
cp -r toxcore-macos-arm64/include/tox toxcore-macos/Tox.framework/Headers
lipo -create -output toxcore-macos/Tox.framework/Tox \
toxcore-macos-arm64/lib/libtoxcore.dylib \
toxcore-macos-x86_64/lib/libtoxcore.dylib
install_name_tool -id @rpath/Tox.framework/Tox toxcore-macos/Tox.framework/Tox
# Make a Tox.xcframework for iOS, iPhone simulator, and macOS.
rm -rf Tox.xcframework
xcodebuild -create-xcframework -output Tox.xcframework \
-framework toxcore-ios/Tox.framework \
-framework toxcore-iphonesimulator/Tox.framework \
-framework toxcore-macos/Tox.framework
# Test the Tox.xcframework.
cat >smoke-test.c <<'EOF'
#include <stdio.h>
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdocumentation-deprecated-sync"
#include <tox/tox.h>
#pragma GCC diagnostic pop
int main(void) {
Tox *tox = tox_new(NULL, NULL);
if (tox == NULL) {
fprintf(stderr, "tox_new failed\n");
return 1;
}
tox_kill(tox);
return 0;
}
EOF
pod lib lint toxcore.podspec
rm smoke-test.c

View File

@ -0,0 +1,24 @@
Pod::Spec.new do |s|
s.name = "toxcore"
s.version = "0.2.20"
s.summary = "Cocoapods wrapper for toxcore"
s.homepage = "https://github.com/TokTok/c-toxcore"
s.license = 'GPLv3'
s.author = { "Iphigenia Df" => "iphydf@gmail.com" }
s.source = {
:git => "https://github.com/TokTok/c-toxcore.git",
:tag => s.version.to_s,
:submodules => true
}
s.requires_arc = false
s.ios.deployment_target = '12.0'
s.osx.deployment_target = '10.15'
s.vendored_frameworks = 'Tox.xcframework'
s.xcconfig = { 'FRAMEWORK_SEARCH_PATHS' => '"${PODS_ROOT}"' }
s.test_spec 'Tests' do |test_spec|
test_spec.source_files = 'smoke-test.c'
end
end

View File

@ -0,0 +1,30 @@
#!/usr/bin/env bash
set -eux -o pipefail
SYSTEM="$1"
ARCH="$2"
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
DEP_PREFIX="$PWD/deps-prefix-$SYSTEM-$ARCH"
if [ -d "$DEP_PREFIX" ]; then
exit 0
fi
if [ -d ../dockerfiles ]; then
DOCKERFILES="$(realpath ../dockerfiles)"
else
git clone --depth=1 https://github.com/TokTok/dockerfiles "$SCRIPT_DIR/dockerfiles"
DOCKERFILES="$SCRIPT_DIR/dockerfiles"
fi
for dep in sodium opus vpx; do
mkdir -p "external/$dep"
pushd "external/$dep"
SCRIPT="$DOCKERFILES/qtox/build_$dep.sh"
"$SCRIPT" --arch "$SYSTEM-$ARCH" --libtype "static" --buildtype "release" --prefix "$DEP_PREFIX" --macos "10.15"
popd
rm -rf "external/$dep"
done

View File

@ -0,0 +1,58 @@
#!/usr/bin/env bash
set -eux -o pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
TARGET="$1"
if [ -n "${CI-}" ]; then
brew install bash coreutils ninja yasm
fi
SYSTEM="${TARGET%%-*}"
ARCH="${TARGET#*-}"
"$SCRIPT_DIR/deps.sh" "$SYSTEM" "$ARCH"
export PKG_CONFIG_PATH="$PWD/deps-prefix-$SYSTEM-$ARCH/lib/pkgconfig"
if [ "$SYSTEM" = "ios" ]; then
XC_SDK="iphoneos"
TARGET_IPHONE_SIMULATOR=OFF
IOS_FLAGS="-miphoneos-version-min=10.0 -arch $ARCH"
elif [ "$SYSTEM" = "iphonesimulator" ]; then
XC_SDK="iphonesimulator"
TARGET_IPHONE_SIMULATOR=ON
IOS_FLAGS="-arch $ARCH"
else
echo "Unexpected system $SYSTEM"
exit 1
fi
BUILD_DIR="_build-$SYSTEM-$ARCH"
# Build for iOS 10
cmake \
-B "$BUILD_DIR" \
-G Ninja \
-DCMAKE_INSTALL_PREFIX="$PWD/toxcore-$SYSTEM-$ARCH" \
-DCMAKE_BUILD_TYPE=Release \
-DENABLE_STATIC=OFF \
-DENABLE_SHARED=ON \
-DMUST_BUILD_TOXAV=ON \
-DDHT_BOOTSTRAP=OFF \
-DBOOTSTRAP_DAEMON=OFF \
-DUNITTEST=OFF \
-DSTRICT_ABI=ON \
-DMIN_LOGGER_LEVEL=TRACE \
-DEXPERIMENTAL_API=ON \
-DCMAKE_C_FLAGS="$IOS_FLAGS" \
-DCMAKE_CXX_FLAGS="$IOS_FLAGS" \
-DCMAKE_EXE_LINKER_FLAGS="$IOS_FLAGS" \
-DCMAKE_SHARED_LINKER_FLAGS="$IOS_FLAGS" \
-DCMAKE_OSX_SYSROOT="$(xcrun --sdk "$XC_SDK" --show-sdk-path)" \
-DCMAKE_OSX_ARCHITECTURES="$ARCH"
cmake --build "$BUILD_DIR"
cmake --install "$BUILD_DIR"

View File

@ -0,0 +1,29 @@
#!/usr/bin/env bash
set -eux -o pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
ARCH="$1"
"$SCRIPT_DIR/deps.sh" linux "$ARCH"
export PKG_CONFIG_PATH="$PWD/deps-prefix-linux-$ARCH/lib/pkgconfig"
# Build
cmake \
-B _build \
-G Ninja \
-DCMAKE_INSTALL_PREFIX="$PWD/toxcore-linux-$ARCH" \
-DCMAKE_BUILD_TYPE=Release \
-DENABLE_STATIC=OFF \
-DENABLE_SHARED=ON \
-DMUST_BUILD_TOXAV=ON \
-DDHT_BOOTSTRAP=OFF \
-DBOOTSTRAP_DAEMON=OFF \
-DUNITTEST=OFF \
-DSTRICT_ABI=ON \
-DMIN_LOGGER_LEVEL=TRACE \
-DEXPERIMENTAL_API=ON
cmake --build _build
cmake --install _build

View File

@ -0,0 +1,37 @@
#!/usr/bin/env bash
set -eux -o pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
ARCH="$1"
if [ -n "${CI-}" ]; then
brew install bash coreutils ninja yasm
fi
"$SCRIPT_DIR/deps.sh" macos "$ARCH"
export PKG_CONFIG_PATH="$PWD/deps-prefix-macos-$ARCH/lib/pkgconfig"
BUILD_DIR="_build-macos-$ARCH"
# Build for macOS
cmake \
-B "$BUILD_DIR" \
-G Ninja \
-DCMAKE_INSTALL_PREFIX="$PWD/toxcore-macos-$ARCH" \
-DCMAKE_BUILD_TYPE=Release \
-DENABLE_STATIC=OFF \
-DENABLE_SHARED=ON \
-DMUST_BUILD_TOXAV=ON \
-DDHT_BOOTSTRAP=OFF \
-DBOOTSTRAP_DAEMON=OFF \
-DUNITTEST=OFF \
-DSTRICT_ABI=ON \
-DMIN_LOGGER_LEVEL=TRACE \
-DEXPERIMENTAL_API=ON \
-DCMAKE_OSX_DEPLOYMENT_TARGET=10.15
cmake --build "$BUILD_DIR"
cmake --install "$BUILD_DIR"

View File

@ -0,0 +1 @@
!/Makefile

View File

@ -0,0 +1,26 @@
TARGETS = libtoxcore.a libtoxcore-minimal.a
all: $(TARGETS)
libtoxcore.o: $(wildcard toxcore-*av.c)
$(CC) -c -o $@ $< \
-O2 \
-Wno-discarded-qualifiers \
-fPIC \
-Wl,-Bstatic \
$(shell pkg-config --cflags --libs libsodium) \
-Wl,-Bdynamic \
$(shell pkg-config --cflags --libs opus vpx) \
-pthread
libtoxcore-minimal.o: $(wildcard toxcore-*core.c)
$(CC) -c -o $@ $< \
-O2 \
-Wno-discarded-qualifiers \
-fPIC \
-Wl,-Bstatic \
$(shell pkg-config --cflags --libs libsodium) \
-pthread
%.a: %.o
$(AR) rcs $@ $^

View File

@ -0,0 +1,60 @@
#!/usr/bin/env perl
#
# This script can be used to create a single .c file with all of toxcore in it
# as well as your code or test file. It does not depend on any header files
# anymore, as those are emitted directly into the .c file.
#
# Example:
#
# other/deploy/single-file/make_single_file auto_tests/toxav_basic_test.c auto_tests/auto_test_support.c testing/misc_tools.c | \
# tcc -o toxav_basic_test - $(pkg-config --cflags --libs libsodium opus vpx)
#
# other/deploy/single-file/make_single_file -core auto_tests/send_message_test.c auto_tests/auto_test_support.c testing/misc_tools.c | \
# tcc -o send_message_test - $(pkg-config --cflags --libs libsodium)
use strict;
use warnings;
use Cwd 'abs_path';
sub relative_to {
my ($rel, $fn) = @_;
my @path = split "/", $rel;
pop @path;
abs_path(join "/", @path, $fn)
}
my %seen;
sub emit {
my ($fn) = @_;
return if $seen{$fn};
$seen{$fn} = 1;
open my $fh, "<", $fn or die "$fn: $!";
my $line = 1;
print "#line $line \"$fn\"\n";
while (<$fh>) {
if (/^#include "([^"]*)"/) {
emit(relative_to($fn, $1), $1);
++$line;
print "#line $line \"$fn\"\n";
} else {
print;
++$line;
}
}
}
my @core = (<toxcore/*.c>, <toxcore/*/*.c>, <toxencryptsave/*.c>, <third_party/cmp/*.c>);
if (@ARGV and $ARGV[0] eq "-core") {
shift @ARGV;
emit(abs_path $_) for @core;
} else {
if (@ARGV and $ARGV[0] eq "-av") {
# Ignore -av, it's the default.
shift @ARGV;
}
emit(abs_path $_) for (<toxav/*.c>, @core);
}
emit(abs_path $_) for @ARGV;