mirror of
https://github.com/signalapp/libsignal.git
synced 2024-09-19 19:42:19 +02:00
Add libsignal-bridge-testing for Swift
Use a similar strategy as for Node, but with an additional crate that serves as the target for running cbindgen. The expectation is that since iOS links with the native signal_ffi statically, the linker will be able to prune out the unsued test-only code.
This commit is contained in:
parent
89547673af
commit
6d3c1b057f
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -2097,6 +2097,7 @@ dependencies = [
|
||||
"cpufeatures",
|
||||
"futures-util",
|
||||
"libsignal-bridge",
|
||||
"libsignal-bridge-testing",
|
||||
"libsignal-net",
|
||||
"libsignal-protocol",
|
||||
"log",
|
||||
|
@ -22,6 +22,7 @@ testing-fns = ["libsignal-bridge/testing-fns"]
|
||||
|
||||
[dependencies]
|
||||
libsignal-bridge = { path = "../shared", features = ["ffi"] }
|
||||
libsignal-bridge-testing = { path = "../shared/testing", features = ["ffi"] }
|
||||
libsignal-net = { path = "../../net" }
|
||||
libsignal-protocol = { path = "../../protocol" }
|
||||
signal-media = { path = "../../media" }
|
||||
|
59
rust/bridge/ffi/cbindgen-testing.toml
Normal file
59
rust/bridge/ffi/cbindgen-testing.toml
Normal file
@ -0,0 +1,59 @@
|
||||
#
|
||||
# Copyright (C) 2024 Signal Messenger, LLC.
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
#
|
||||
|
||||
language = "C"
|
||||
|
||||
header = "/*\nCopyright (C) 2024 Signal Messenger, LLC.\nSPDX-License-Identifier: AGPL-3.0-only\n*/\n"
|
||||
|
||||
include_guard = "SIGNAL_FFI_TESTING_H_"
|
||||
|
||||
autogen_warning = "/* This file was automatically generated by cbindgen */"
|
||||
|
||||
includes = ["signal_ffi.h"]
|
||||
|
||||
style = "type"
|
||||
|
||||
usize_is_size_t = true
|
||||
|
||||
[defines]
|
||||
"feature = signal-media" = "SIGNAL_MEDIA_SUPPORTED"
|
||||
|
||||
[enum]
|
||||
prefix_with_name = true
|
||||
|
||||
[export]
|
||||
exclude = ["TAG_SIZE", "NONCE_SIZE"]
|
||||
item_types = [
|
||||
"enums",
|
||||
"functions",
|
||||
"opaque",
|
||||
"structs",
|
||||
"typedefs",
|
||||
"constants",
|
||||
]
|
||||
# FIXME: this doesn't work well with constants in SCREAMING_SNAKE_CASE
|
||||
prefix = "Signal"
|
||||
renaming_overrides_prefixing = true
|
||||
|
||||
[export.rename]
|
||||
# Avoid double-prefixing these
|
||||
"SignalFfiError" = "SignalFfiError"
|
||||
"SignalErrorCode" = "SignalErrorCode"
|
||||
|
||||
[export.mangle]
|
||||
remove_underscores = true
|
||||
|
||||
[fn]
|
||||
sort_by = "None"
|
||||
args = "horizontal"
|
||||
|
||||
[parse]
|
||||
parse_deps = true
|
||||
include = []
|
||||
extra_bindings = ["libsignal-bridge-testing"]
|
||||
|
||||
[parse.expand]
|
||||
crates = ["libsignal-bridge-testing"]
|
||||
features = ["libsignal-bridge-testing/ffi"]
|
@ -8,6 +8,8 @@
|
||||
|
||||
use futures_util::FutureExt;
|
||||
use libsignal_bridge::ffi::*;
|
||||
#[allow(unused_imports)]
|
||||
use libsignal_bridge_testing::*;
|
||||
use libsignal_protocol::*;
|
||||
|
||||
use std::ffi::{c_char, c_uchar, c_uint, CString};
|
||||
|
@ -4,5 +4,6 @@
|
||||
//
|
||||
module SignalFfi {
|
||||
header "signal_ffi.h"
|
||||
header "signal_ffi_testing.h"
|
||||
link "signal_ffi"
|
||||
}
|
||||
|
21
swift/Sources/SignalFfi/signal_ffi_testing.h
Normal file
21
swift/Sources/SignalFfi/signal_ffi_testing.h
Normal file
@ -0,0 +1,21 @@
|
||||
/*
|
||||
Copyright (C) 2024 Signal Messenger, LLC.
|
||||
SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
|
||||
#ifndef SIGNAL_FFI_TESTING_H_
|
||||
#define SIGNAL_FFI_TESTING_H_
|
||||
|
||||
/* This file was automatically generated by cbindgen */
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include "signal_ffi.h"
|
||||
|
||||
SignalFfiError *signal_test_only_fn_returns_123(uint32_t *out);
|
||||
|
||||
#endif /* SIGNAL_FFI_TESTING_H_ */
|
16
swift/Tests/LibSignalClientTests/NativeTests.swift
Normal file
16
swift/Tests/LibSignalClientTests/NativeTests.swift
Normal file
@ -0,0 +1,16 @@
|
||||
//
|
||||
// Copyright 2024 Signal Messenger, LLC.
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
//
|
||||
|
||||
import Foundation
|
||||
@testable import LibSignalClient
|
||||
import SignalFfi
|
||||
import XCTest
|
||||
|
||||
final class NativeTests: XCTestCase {
|
||||
func testTestingFnsAreAvailable() async throws {
|
||||
let output = try invokeFnReturningInteger(fn: SignalFfi.signal_test_only_fn_returns_123)
|
||||
XCTAssertEqual(output, 123)
|
||||
}
|
||||
}
|
@ -134,6 +134,7 @@ fi
|
||||
echo_then_run cargo build -p libsignal-ffi ${RELEASE_BUILD:+--release} ${VERBOSE:+--verbose} ${CARGO_BUILD_TARGET:+--target $CARGO_BUILD_TARGET} ${FEATURES:+--features "${FEATURES[*]}"} ${BUILD_STD:+-Zbuild-std}
|
||||
|
||||
FFI_HEADER_PATH=swift/Sources/SignalFfi/signal_ffi.h
|
||||
FFI_TESTING_HEADER_PATH=swift/Sources/SignalFfi/signal_ffi_testing.h
|
||||
|
||||
if [[ -n "${SHOULD_CBINDGEN}" ]]; then
|
||||
check_cbindgen
|
||||
@ -145,6 +146,12 @@ if [[ -n "${SHOULD_CBINDGEN}" ]]; then
|
||||
echo 'error: signal_ffi.h not up to date; run' "$0" '--generate-ffi' >&2
|
||||
exit 1
|
||||
fi
|
||||
echo diff -u "${FFI_TESTING_HEADER_PATH}" "<(cbindgen -q ${RELEASE_BUILD:+--profile release} rust/bridge/shared/testing --config rust/bridge/ffi/cbindgen-testing.toml)"
|
||||
if ! diff -u "${FFI_TESTING_HEADER_PATH}" <(cbindgen -q ${RELEASE_BUILD:+--profile release} rust/bridge/shared/testing --config rust/bridge/ffi/cbindgen-testing.toml); then
|
||||
echo
|
||||
echo 'error: signal_ffi_testing.h not up to date; run' "$0" '--generate-ffi' >&2
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
echo cbindgen ${RELEASE_BUILD:+--profile release} -o "${FFI_HEADER_PATH}" rust/bridge/ffi
|
||||
# Use sed to ignore irrelevant cbindgen warnings.
|
||||
@ -152,5 +159,10 @@ if [[ -n "${SHOULD_CBINDGEN}" ]]; then
|
||||
# shellcheck disable=SC2016
|
||||
cbindgen ${RELEASE_BUILD:+--profile release} -o "${FFI_HEADER_PATH}" rust/bridge/ffi 2>&1 |
|
||||
sed '/WARN: Missing `\[defines\]` entry for `feature = "ffi"` in cbindgen config\./ d' >&2
|
||||
|
||||
echo cbindgen ${RELEASE_BUILD:+--profile release} -o "${FFI_TESTING_HEADER_PATH}" rust/bridge/shared/testing --config rust/bridge/ffi/cbindgen-testing.toml
|
||||
# shellcheck disable=SC2016
|
||||
cbindgen ${RELEASE_BUILD:+--profile release} -o "${FFI_TESTING_HEADER_PATH}" rust/bridge/shared/testing --config rust/bridge/ffi/cbindgen-testing.toml 2>&1 |
|
||||
sed '/WARN: Missing `\[defines\]` entry for `feature = "ffi"` in cbindgen config\./ d' >&2
|
||||
fi
|
||||
fi
|
||||
|
Loading…
Reference in New Issue
Block a user