Skip to content

Commit

Permalink
Merge branch 'dev-0.17'
Browse files Browse the repository at this point in the history
  • Loading branch information
birdofpreyru committed Sep 9, 2024
2 parents 762eb1b + de7fe61 commit ce6cd19
Show file tree
Hide file tree
Showing 15 changed files with 1,476 additions and 352 deletions.
23 changes: 23 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,29 @@ if(CMAKE_SYSTEM_NAME MATCHES "Android")
)
endif()

# Builds & places for packing the glob library, for Android-targeted builds.
if(CMAKE_SYSTEM_NAME MATCHES "Android")
execute_process(
COMMAND ${CMAKE_COMMAND} ${CMAKE_CURRENT_SOURCE_DIR}/glob
-B ${CMAKE_BINARY_DIR}/glob
-DCMAKE_BUILD_TYPE=Release
-DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/sysroot
-DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}
${EXTRA_BUILD_ARGS}
COMMAND_ECHO STDOUT
COMMAND_ERROR_IS_FATAL ANY
)
execute_process(
COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR}/glob
--config Release ${EXTRA_INSTALL_ARGS}
)
execute_process(COMMAND ${CMAKE_COMMAND} --install ${CMAKE_BINARY_DIR}/glob)
file(
COPY ${CMAKE_BINARY_DIR}/sysroot/lib/libglob.so
DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/android/src/main/jniLibs/${ANDROID_ABI}
)
endif()

if(CMAKE_SYSTEM_NAME MATCHES "Android|Windows")
set(BUILD_SHARED_LIBS 1)
endif()
Expand Down
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,6 @@ and [old][Old Architecture] RN architectures.
from NPM._
- For **Android**:
- In the `build.gradle` file set `minSdkVersion` equal `28`
([SDK 28 — Android 9](https://developer.android.com/studio/releases/platforms#9.0),
released in August 2018), or larger. \
**Note:** _Support of older SDKs is technically possible, but it is not
a priority now._
- Android SDK 28 and above
[forbids Cleartext / Plaintext HTTP](https://developer.android.com/privacy-and-security/risks/cleartext)
by default. Thus, to access locally running server over HTTP from within
Expand Down
11 changes: 5 additions & 6 deletions android/src/main/java/com/lighttpd/Server.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.lighttpd

import android.util.Log
import com.drpogodin.reactnativestaticserver.Errors
import java.util.function.BiConsumer

/**
* Java interface for native Lighttpd server running in a dedicated Thread.
Expand All @@ -25,7 +24,7 @@ class Server(
val id: Double,
var configPath: String,
var errlogPath: String,
private val signalConsumer: BiConsumer<String, String?>
private val signalConsumer: (signal: String, message: String?) -> Unit
) : Thread() {
override fun interrupt() {
Log.i(LOGTAG, "Server.interrupt() triggered")
Expand All @@ -42,7 +41,7 @@ class Server(
if (activeServer != null) {
val msg = "Another Server instance is active"
Log.e(LOGTAG, msg)
signalConsumer.accept(CRASHED, msg)
signalConsumer(CRASHED, msg)
return
}
try {
Expand All @@ -56,11 +55,11 @@ class Server(
// signals.
activeServer = null
Log.i(LOGTAG, "Server terminated gracefully")
signalConsumer.accept(TERMINATED, null)
signalConsumer(TERMINATED, null)
} catch (error: Exception) {
activeServer = null
Log.e(LOGTAG, "Server crashed", error)
signalConsumer.accept(CRASHED, error.message)
signalConsumer(CRASHED, error.message)
}
}

Expand All @@ -79,7 +78,7 @@ class Server(
// NOTE: @JvmStatic annotation is needed to make this function
// visible via JNI in C code.
@JvmStatic fun onLaunchedCallback() {
activeServer!!.signalConsumer.accept(LAUNCHED, null)
activeServer!!.signalConsumer(LAUNCHED, null)
}
}
}
2 changes: 1 addition & 1 deletion example/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
buildscript {
ext {
buildToolsVersion = "34.0.0"
minSdkVersion = 28
minSdkVersion = 23
compileSdkVersion = 34
targetSdkVersion = 34
ndkVersion = "26.1.10909125"
Expand Down
8 changes: 4 additions & 4 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ PODS:
- ReactCommon/turbomodule/bridging
- ReactCommon/turbomodule/core
- Yoga
- dr-pogodin-react-native-static-server (0.16.0):
- dr-pogodin-react-native-static-server (0.17.0):
- DoubleConversion
- glog
- hermes-engine
Expand Down Expand Up @@ -1279,7 +1279,7 @@ PODS:
- ReactCommon/turbomodule/bridging
- ReactCommon/turbomodule/core
- Yoga
- react-native-webview (13.11.1):
- react-native-webview (13.12.1):
- DoubleConversion
- glog
- hermes-engine
Expand Down Expand Up @@ -1773,7 +1773,7 @@ SPEC CHECKSUMS:
boost: 4cb898d0bf20404aab1850c656dcea009429d6c1
DoubleConversion: 76ab83afb40bddeeee456813d9c04f67f78771b5
dr-pogodin-react-native-fs: d4852b7b2d5f6a9d40627dce4a8a30f865634eef
dr-pogodin-react-native-static-server: f4c365cf9e5ba07fd0d10504572f661039562ba3
dr-pogodin-react-native-static-server: fbba57f5167d431e10644029cb8efd45a45a06f2
FBLazyVector: 38bb611218305c3bc61803e287b8a81c6f63b619
fmt: 4c2741a687cc09f0634a2e2c72a838b99f1ff120
glog: 69ef571f3de08433d766d614c73a9838a06bf7eb
Expand Down Expand Up @@ -1807,7 +1807,7 @@ SPEC CHECKSUMS:
React-logger: 8db32983d75dc2ad54f278f344ccb9b256e694fc
React-Mapbuffer: 1c08607305558666fd16678b85ef135e455d5c96
React-microtasksnativemodule: f13f03163b6a5ec66665dfe80a0df4468bb766a6
react-native-webview: 8e4d4384fe7c702804d6b3d3d21b1fa98077cd7e
react-native-webview: 987318278133db89939305abefc47ebb28ed4af8
React-nativeconfig: 57781b79e11d5af7573e6f77cbf1143b71802a6d
React-NativeModulesApple: 7ff2e2cfb2e5fa5bdedcecf28ce37e696c6ef1e1
React-perflogger: 8a360ccf603de6ddbe9ff8f54383146d26e6c936
Expand Down
8 changes: 4 additions & 4 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@
},
"dependencies": {
"@dr.pogodin/react-native-fs": "^2.28.0",
"@dr.pogodin/react-native-webview": "^13.11.1",
"@dr.pogodin/react-native-webview": "^13.12.1",
"react": "18.3.1",
"react-native": "0.75.2",
"react-native-windows": "0.75.0"
"react-native-windows": "0.75.1"
},
"devDependencies": {
"@babel/core": "^7.25.2",
"@babel/preset-env": "^7.25.4",
"@babel/runtime": "^7.25.4",
"@babel/runtime": "^7.25.6",
"@react-native/babel-preset": "0.75.2",
"@react-native/metro-config": "0.75.2",
"@react-native/typescript-config": "0.75.2",
"metro-config": "^0.80.10",
"metro-config": "^0.80.12",
"react-native-builder-bob": "^0.30.0"
},
"engines": {
Expand Down
14 changes: 14 additions & 0 deletions glob/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
project(GLOB C)

set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED TRUE)

set(HEADERS collate.h freebsd-compat.h glob.h)
set(SOURCES glob.c)

add_compile_definitions(__USE_BSD)
add_library(glob ${HEADERS} ${SOURCES})

install(TARGETS glob)
install(FILES ${HEADERS} DESTINATION include)
5 changes: 5 additions & 0 deletions glob/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
The Glob library is a part of Android SDK starting from SDK 28; thus, to support
older SDKs we compile it from sources. These source files are taken from
the https://android.googlesource.com/platform/bionic repository
([bionic](https://en.wikipedia.org/wiki/Bionic_%28software%29)
is Android's C library, math library, and dynamic linker).
26 changes: 26 additions & 0 deletions glob/collate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include "freebsd-compat.h"

/**
* [reallocarray(3)](https://man7.org/linux/man-pages/man3/realloc.3.html) resizes
* allocated memory on the heap.
*
* Equivalent to `realloc(__ptr, __item_count * __item_size)` but fails if the
* multiplication overflows.
*
* Returns a pointer (which may be different from `__ptr`) to the resized
* memory on success and returns a null pointer and sets `errno` on failure
* (but see the notes for malloc()).
*/
#if __ANDROID_API__ >= 29
void* _Nullable reallocarray(void* _Nullable __ptr, size_t __item_count, size_t __item_size) __BIONIC_ALLOC_SIZE(2, 3) __INTRODUCED_IN(29);
#else
#include <errno.h>
static __inline void* _Nullable reallocarray(void* _Nullable __ptr, size_t __item_count, size_t __item_size) {
size_t __new_size;
if (__builtin_mul_overflow(__item_count, __item_size, &__new_size)) {
errno = ENOMEM;
return NULL;
}
return realloc(__ptr, __new_size);
}
#endif
26 changes: 26 additions & 0 deletions glob/freebsd-compat.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright (C) 2013 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#pragma once

#define _BSD_SOURCE

#define REPLACE_GETOPT

/* FreeBSD has this, but we can't really implement it correctly on Linux. */
#define issetugid() 0

#define __compiler_membar() __asm __volatile(" " : : : "memory")
Loading

0 comments on commit ce6cd19

Please sign in to comment.