Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
build/
dist/
out/
build_ios/

# IDE and editor files
.vscode/
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "vibe-writing-workflow"]
path = vibe-writing-workflow
url = https://github.com/zerosrat/vibe-writing-workflow.git
87 changes: 67 additions & 20 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,17 @@ set(COMMON_SOURCES

# 平台特定源文件
if(APPLE)
set(PLATFORM_SOURCES
src/macos/modules/deviceinfo/DeviceInfoModule.mm
)
# 根据具体平台选择源文件
if(${CMAKE_SYSTEM_NAME} MATCHES "iOS")
set(PLATFORM_SOURCES
src/ios/modules/deviceinfo/DeviceInfoModule.mm
)
else()
# macOS
set(PLATFORM_SOURCES
src/macos/modules/deviceinfo/DeviceInfoModule.mm
)
endif()
# 设置 Objective-C++ 编译标志
set_source_files_properties(${PLATFORM_SOURCES}
PROPERTIES COMPILE_FLAGS "-fobjc-arc")
Expand Down Expand Up @@ -63,37 +71,45 @@ if(APPLE)
message(FATAL_ERROR "JavaScriptCore framework not found")
endif()

# 查找并链接 IOKit 框架 (DeviceInfo 模块需要)
find_library(IOKIT_FRAMEWORK IOKit)
if(NOT IOKIT_FRAMEWORK)
message(FATAL_ERROR "IOKit framework not found")
endif()

# 查找并链接 Foundation 框架
# 查找并链接 Foundation 框架 (所有 Apple 平台共用)
find_library(FOUNDATION_FRAMEWORK Foundation)
if(NOT FOUNDATION_FRAMEWORK)
message(FATAL_ERROR "Foundation framework not found")
endif()

# 平台特定框架
if(${CMAKE_SYSTEM_NAME} MATCHES "iOS")
# iOS 特定框架
find_library(UIKIT_FRAMEWORK UIKit)
if(NOT UIKIT_FRAMEWORK)
message(FATAL_ERROR "UIKit framework not found")
endif()
set(PLATFORM_FRAMEWORKS ${UIKIT_FRAMEWORK})
else()
# macOS 特定框架
find_library(IOKIT_FRAMEWORK IOKit)
if(NOT IOKIT_FRAMEWORK)
message(FATAL_ERROR "IOKit framework not found")
endif()
set(PLATFORM_FRAMEWORKS ${IOKIT_FRAMEWORK})
endif()

# 链接所需框架
target_link_libraries(mini_react_native
${JAVASCRIPTCORE_FRAMEWORK}
${IOKIT_FRAMEWORK}
${FOUNDATION_FRAMEWORK}
${PLATFORM_FRAMEWORKS}
)

# macOS 特定设置
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
# 平台特定部署目标设置
if(${CMAKE_SYSTEM_NAME} MATCHES "iOS")
set(CMAKE_OSX_DEPLOYMENT_TARGET "12.0")
message(STATUS "Building for iOS with deployment target: ${CMAKE_OSX_DEPLOYMENT_TARGET}")
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.15")
message(STATUS "Building for macOS with deployment target: ${CMAKE_OSX_DEPLOYMENT_TARGET}")
endif()

# iOS 特定设置 (暂时注释,专注 macOS)
# if(${CMAKE_SYSTEM_NAME} MATCHES "iOS")
# set(CMAKE_OSX_DEPLOYMENT_TARGET "11.0")
# message(STATUS "Building for iOS with deployment target: ${CMAKE_OSX_DEPLOYMENT_TARGET}")
# endif()

elseif(ANDROID)
# Android 配置 (未来实现)
message(STATUS "Android build configuration - TODO")
Expand All @@ -117,10 +133,41 @@ target_include_directories(test_module_framework PRIVATE src)
target_link_libraries(test_module_framework mini_react_native)

# 集成测试可执行文件(使用打包后的 JavaScript bundle)
add_executable(test_integration examples/test_integration.cpp)
if(${CMAKE_SYSTEM_NAME} MATCHES "iOS")
# iOS版本需要包含Objective-C helper文件
add_executable(test_integration examples/test_integration.cpp examples/ios_bundle_helper.mm)
else()
# 其他平台只需要C++文件
add_executable(test_integration examples/test_integration.cpp)
endif()
target_include_directories(test_integration PRIVATE src)
target_link_libraries(test_integration mini_react_native)

# 性能测试可执行文件(轻量级性能检查)
add_executable(test_performance examples/test_performance.cpp)
target_include_directories(test_performance PRIVATE src)
target_link_libraries(test_performance mini_react_native)

# iOS 特定配置:复制 JavaScript bundle 到应用包
if(${CMAKE_SYSTEM_NAME} MATCHES "iOS")
# 为 test_integration 添加 bundle.js 资源复制
add_custom_command(TARGET test_integration POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${CMAKE_SOURCE_DIR}/dist/bundle.js"
"$<TARGET_FILE_DIR:test_integration>/bundle.js"
COMMENT "Copying JavaScript bundle to iOS app package"
)

# 为 test_integration 添加测试脚本复制
add_custom_command(TARGET test_integration POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${CMAKE_SOURCE_DIR}/examples/scripts/test_deviceinfo.js"
"$<TARGET_FILE_DIR:test_integration>/test_deviceinfo.js"
COMMENT "Copying test script to iOS app package"
)
endif()


# 安装配置(make install 时才会执行)
# 安装静态库到 /usr/local/lib 下
install(TARGETS mini_react_native
Expand Down
53 changes: 52 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,39 @@ build: js-build configure
@cd $(BUILD_DIR) && make -j$(CORES)
@echo "✅ Build complete"

# iOS 构建配置(模拟器)
.PHONY: ios-configure
ios-configure:
@echo "🔧 Configuring iOS build system..."
@mkdir -p $(BUILD_DIR)_ios
@cd $(BUILD_DIR)_ios && DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer cmake \
-DCMAKE_SYSTEM_NAME=iOS \
-DCMAKE_OSX_ARCHITECTURES=$$(uname -m) \
-DCMAKE_OSX_SYSROOT=$$(DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer xcrun --sdk iphonesimulator --show-sdk-path) \
-DCMAKE_BUILD_TYPE=$(CMAKE_BUILD_TYPE) \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
..
@echo "✅ iOS configuration complete"

# 构建 iOS 版本(模拟器)
.PHONY: ios-build
ios-build: js-build ios-configure
@echo "🔨 Building Mini React Native for iOS..."
@cd $(BUILD_DIR)_ios && make -j$(CORES)
@echo "✅ iOS build complete"

# iOS 测试目标
.PHONY: ios-test
ios-test: ios-build
@echo "🍎 Running iOS tests..."
@./test_ios.sh all

# iOS DeviceInfo 测试
.PHONY: ios-test-deviceinfo
ios-test-deviceinfo: ios-build
@echo "🍎 Running iOS DeviceInfo test..."
@./test_ios.sh deviceinfo

# 运行测试
# 执行顺序:configure → build → test
.PHONY: test
Expand All @@ -64,6 +97,8 @@ test: build
@./$(BUILD_DIR)/test_module_framework
@echo "\n📝 Test 3: Integration test"
@./$(BUILD_DIR)/test_integration
@echo "\n📝 Test 4: Performance test"
@./$(BUILD_DIR)/test_performance
@echo "\n✅ All tests complete"

# 运行基础测试
Expand All @@ -87,11 +122,18 @@ test-integration: build
@./$(BUILD_DIR)/test_integration
@echo "✅ Integration test complete"

# 运行性能测试
.PHONY: test-performance
test-performance: build
@echo "🧪 Running performance test..."
@./$(BUILD_DIR)/test_performance
@echo "✅ Performance test complete"

# 清理构建文件
.PHONY: clean
clean: js-clean
@echo "🧹 Cleaning build files..."
@rm -rf $(BUILD_DIR)
@rm -rf $(BUILD_DIR) $(BUILD_DIR)_ios
@echo "✅ Clean complete"

# 完全重建
Expand Down Expand Up @@ -160,11 +202,20 @@ help:
@echo " make rebuild - 完全重新构建"
@echo " make configure - 仅配置 CMake"
@echo ""
@echo "iOS 构建命令:"
@echo " make ios-build - 构建 iOS 版本(模拟器)"
@echo " make ios-configure - 仅配置 iOS 构建"
@echo ""
@echo "iOS 测试命令:"
@echo " make ios-test - 运行所有 iOS 测试"
@echo " make ios-test-deviceinfo - 运行 iOS DeviceInfo 测试"
@echo ""
@echo "测试命令:"
@echo " make test - 运行所有测试"
@echo " make test-basic - 仅运行基础功能测试"
@echo " make test-module - 仅运行模块框架测试"
@echo " make test-integration - 仅运行集成测试"
@echo " make test-performance - 仅运行性能测试"
@echo ""
@echo "开发工具:"
@echo " make install-deps - 安装开发依赖"
Expand Down
116 changes: 57 additions & 59 deletions claude.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@
- 尽快建立反馈循环,验证设计思路
- 允许后续重构和改进

4. **AI 协助开发** > 纯手工编码
- 利用 AI 生成大部分基础代码和样板代码
- 人工专注于架构设计和核心逻辑
- 显著提升开发效率,缩短实现周期

## 🔧 开发策略

### 质量标准
Expand Down Expand Up @@ -57,81 +52,84 @@

具体的,桥架构版本参考 RN [v0.57.8](https://github.com/facebook/react-native/blob/0.57-stable/Libraries/BatchedBridge/MessageQueue.js),这个版本只包含 Bridge 代码不包含 JSI 代码,便于学习和参考。

**核心约束:**
## 关键项目路径

1. **架构思路与 RN 保持一致**
- 遵循官方 RN Bridge 的设计模式和数据流向
- JavaScript ↔ Native 通信必须基于异步消息队列
- 模块注册和方法导出方式与 RN 保持一致
### 核心源码

2. **具体实现可以简化**
- 在保持架构思路一致的前提下,实现细节可以更简单
- 减少复杂的优化和边缘情况处理
- 专注核心流程,忽略生产级的健壮性要求
- `src/common/` - 跨平台核心代码(JSCExecutor、模块系统)
- `src/js/` - JavaScript 实现(MessageQueue、NativeModule 等)
- `src/macos/` - macOS 平台代码
- `src/ios/` - iOS 平台代码
- `src/android/` - Android 平台代码

### 关键组件对应关系
### 构建输出

| 组件 | React Native 原版 | Mini 实现 | 一致性要求 |
|------|------------------|-----------|------------|
| **JSCExecutor** | JSCExecutor.cpp | 简化版 JSCExecutor | JavaScript 上下文管理方式一致 |
| **MessageQueue** | MessageQueue.js | 简化版 MessageQueue | 消息格式和队列机制一致 |
| **NativeModule** | NativeModule.java/.mm | 简化版 NativeModule | 模块注册和方法调用方式一致 |
| **EventEmitter** | RCTEventEmitter | 简化版事件系统 | 事件分发机制一致 |
- `build/` - macOS 构建目录
- `build_ios/` - iOS 构建目录
- `dist/bundle.js` - JavaScript 打包文件

### 兼容性目标
### 测试和示例
- `examples/` - 测试用例和示例代码

- **消息格式兼容**: 能够处理标准 RN 的消息队列格式
- **模块接口兼容**: Native 模块的导出方式与 RN 保持一致
- **JavaScript 接口兼容**: 能够运行基础的 RN-style JavaScript 代码
- **事件系统兼容**: 事件的注册、监听、分发与 RN 行为一致
### 关键配置

## 📅 时间管理
- `CMakeLists.txt` - CMake 构建配置
- `Makefile` - 构建自动化脚本
- `package.json` - Node.js 依赖
- `rollup.config.js` - JavaScript 打包配置

### 总体目标
## 命令

- **阶段1 (Bridge通信)**: 7-10天 (而非原计划的 19-27天)
- **快速原型**: 2-3天内建立基础通信
- **功能完善**: 4-5天完善核心功能
- **验证测试**: 1-2天集成测试
### 构建命令

### 里程碑设定
```bash
make build # 编译项目(默认包含 JS 构建)
make js-build # 仅构建 JavaScript bundle
make js-watch # 监听 JS 文件并自动重建
make clean # 清理所有构建文件
make js-clean # 仅清理 JavaScript 构建文件
make rebuild # 完全清理重建
make configure # 仅配置 CMake
```

每个里程碑都应该有可演示的成果:
- **M1**: JavaScript 能调用一个 Native 函数并获得返回值
- **M2**: Native 能向 JavaScript 发送事件
- **M3**: 完整的 DeviceInfo 模块演示
- **M4**: 性能基准和文档总结
### iOS 构建命令

## 🚀 成功标准
```bash
make ios-build # 为 iOS 模拟器构建
make ios-configure # 仅配置 iOS 构建
```

### 最小成功标准 (Must Have)
### macos 测试命令

- [x] JavaScript ↔ Native 双向通信正常工作
- [x] 至少一个完整的 Native 模块实现 (DeviceInfo)
- [x] 基础的错误处理机制
- [x] 可运行的端到端演示
```bash
make test # 运行所有测试(基础、模块、集成、性能)
make test-basic # 仅基础功能测试
make test-module # 仅模块框架测试
make test-integration # 仅集成测试
make test-performance # 仅性能测试
make ios-test # 运行所有 iOS 测试
make ios-test-deviceinfo # 仅运行 iOS DeviceInfo 测试
```

### 期望标准 (Should Have)
### iOS 测试

- [x] 性能达到可接受水平 (< 10ms 调用延迟)
- [x] 事件系统正常工作
- [x] 基础的调试和日志功能
- [x] 与 React Native 行为对比分析
`docs/iOS_TESTING.md`

### 理想标准 (Could Have)
### 构建系统详情

- [x] 多平台支持 (macOS + iOS)
- [x] 性能优化和内存管理
- [x] 完整的文档和教程
- [x] 开源社区反馈
- 构建类型:基于 CMake(3.15+)
- 编译器:Clang++(C++17 标准)
- 构建目录:`build/`(macOS)、`build_ios/`(iOS)
- 并行构建:自动使用系统 CPU 核心数
- 部署目标:macOS 10.15+、iOS 12.0+

## 📝 文档输出
## 关键文档索引

### 必需文档
- 路线图:`docs/ROADMAP.md`
- 阶段一规划:`docs/PHASE1_PLAN.md`
- 阶段二规划:`docs/PHASE2_PLAN.md`

1. **实现文档**: 记录关键技术决策和实现细节
2. **使用指南**: 如何构建、运行和测试项目
3. **对比分析**: 与官方 React Native 的差异分析
## 📝 文档输出

### 期望文档

Expand Down
Loading