# flujs_libs_quickjs **Repository Path**: flujs_project/flujs_libs_quickjs ## Basic Information - **Project Name**: flujs_libs_quickjs - **Description**: quickjs binary library - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-12-28 - **Last Updated**: 2025-03-07 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ### quickjs-ng xmake 构建 > 使用 xmake 的优势: 自动探测构建工具链(只需要指定构建目标平台即可)、 > 此文档中的 `xmake.lua` 即是 `quickjs-ng` 的 xmake 构建脚本 1、将 `xmake.lua` 复制到项目根目录 2、依次执行 ```sh xmake f -p android -a arm64 xmake b # 或者 xmake package -P .(最终会生成 xrepo 格式的构建产物) ``` 如果要交叉编译所有平台(android、iOS、macos、iphoneos、windows、linux), 可以看到需要执行很多次 `xmake f` 配置. 所以这里自定义了一个交叉编译工具,可以一键生成对应平台的所有架构产物.源码见 `plugins/xross/xmake.lua`. ```sh Usage: $xmake xross [platform] [arch] build cross platform Common options: -q, --quiet Quiet operation. -y, --yes Input yes by default if need user confirm. --confirm=CONFIRM Input the given result if need user confirm. - yes - no - def -v, --verbose Print lots of verbose information for users. --root Allow to run xmake as root. -D, --diagnosis Print lots of diagnosis information (backtrace, check info ..) only for developers. And we can append -v to get more whole information. e.g. $ xmake -vD -h, --help Print this help message and exit. -F FILE, --file=FILE Read a given xmake.lua file. -P PROJECT, --project=PROJECT Change to the given project directory. Search priority: 1. The Given Command Argument 2. The Envirnoment Variable: XMAKE_PROJECT_DIR 3. The Current Directory Command options (xross): -p, platform target platform. iphoneos|linux|macosx|mingw|android -a, arch target arch. iphoneos: armv7|armv7s|arm64|i386|x86_64 linux: arm64|x86_64 macosx: arm64|x86_64 mingw: arm64|x86_64 android: arm64-v8a|armeabi-v7a|x86_64 -ar, --archive xcode archive -d, --debug debug build mode. (default relase) (default: debug mode) -v, --verbose verbose mode. ``` ### quickjs-ng xmake 交叉编译 1、在 macos arm 平台上编译 macos、iphoneos、android 产物 ```sh xmake xross -p macos xmake xross -p iphoneos xmake xross -p android ``` 2、在 macos 上通过 orbstack 创建两个 ubuntu x86 系统 在 ubuntu x86 上可以编译 linux arm/x86 产物, windows (mingw) x86 架构. (ubuntu arm 架构只能编译 linux arm 产物) 先安装 clang、mingw ```sh sudo apt-get update -y && sudo apt-get upgrade -y sudo apt install build-essentials mingw-w64 clang # 多说一句 # 如果要构建 flutter linux 产物,可以执行以下命令 # sudo apt-get install wget clang cmake git ninja-build pkg-config libgtk-3-dev liblzma-dev libstdc++-12-dev -y # wget https://storage.googleapis.com/flutter_infra_release/releases/stable/linux/flutter_linux_3.24.4-stable.tar.xz # tar xf flutter_linux_3.24.4-stable.tar.xz # mv flutter ~ # mv flutter_linux_3.24.4-stable.tar.xz ~ # cd ~ # vim ~/.bashrc # export PATH=$PATH:$HOME/flutter/bin # source ~/.bashrc # flutter --disable-analytics # flutter doctor # 如果引入了 libmpv 库,linux 还需要安装以下内容 # sudo apt install snapd # sudo snap install mpv # sudo apt install -y libmpv-dev libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev ``` ```sh xmake xross -p linux xmake xross -p mingw ``` #### darwin 平台 xcframework 创建 由于预编译二进制文件无法在 macOS/iOS 的 podspec 中获取到对应构建平台的CPU架构(这里指 flutter 框架), 所以通过将所有支持的架构打包为 xcframework, 由 darwin 平台自动识别. 1、将 iOS、macOS 生成好的 framework 按照以下目录整理 ```sh - ios_arm64/qjs.framework - ios_armv7/qjs.framework - ios_armv7s/qjs.framework # - ios_i386/qjs.framework # - ios_x86_64/qjs.framework - macos_arm64/qjs.framework - macos_x86_64/qjs.framework ``` > 其中 ios 需要将 i386、x86_64 位架构移除,原因如下 2、创建输出目录 ```sh mkdir -p ios_universal/qjs.framework/ macos_universal/qjs.framework/ ``` > 必须提前创建好 3、分别创建 ios、macos fat framework ```sh lipo -create ios_arm64/qjs.framework/qjs ios_armv7/qjs.framework/qjs ios_armv7s/qjs.framework/qjs -output ios_universal/qjs.framework/qjs # 这里加上 ios_i386 ios_x86_64 也是能成功创建 fat framework 的 lipo -create macos_arm64/qjs.framework macos_x86_64/qjs.framework -output macos_universal/qjs.framework lipo -info ios_universal/qjs.framework/qjs lipo -info macos_universal/qjs.framework/qjs # 检查 fat framework 架构 ``` > 命令行不要使用 \ 换行,否则报错 ? ```sh error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/lipo: no output file specified usage: lipo [ ...] command is one of: -archs -create -detailed_info -extract [-extract ...] -extract_family [-extract_family ...] -info -remove [-remove ...] -replace [-replace ...] -thin -verify_arch ... options are one or more of: -arch -hideARM64 -output -segalign zsh: exec format error: ios_arm64/qjs.framework/qjs ``` 4、合并生成 xcframework ```sh xcodebuild -create-xcframework -framework ios_universal/qjs.framework -framework macos_universal/qjs.framework -output qjs.xcframework xcframework successfully written out to: /Users/humphrey/Project/Fork/Native/quickjs/build/qjs.xcframework/qjs.xcframework ``` > 如果上面的 fat framework 里包含了*不正确的架构*, 这一步就会报错 error: binaries with multiple platforms are not supported '/Users/humphrey/Project/Fork/Native/quickjs/build/qjs.xcframework/ios_universal/qjs.framework/qjs' > 1、比如 ios 中包含了 i386、x86_64, > 2、ios fat framework 中包含了 macos framework 或者反之. > 如此就需要将多余的 framework 去掉 > `lipo ios_universal/qjs.framework/qjs -remove x86_64 -output ios_universal/qjs.framework/qjs lipo ios_universal/qjs.framework/qjs -remove i386 -output ios_universal/qjs.framework/qjs ` ### 附 #### 自定义插件配置 xmake 自定义插件支持三种方式,可以被 xmake 识别到 1、自定义插件放置到 xmake 的插件安装目录 `xmake/plugins`(里面都是内置的插件) 2、自定义插件保存到 `~/.xmake/plugins` 用户全局目录,这样对当前 xmake 全局生效 3、自定义插件保存到当前项目的 `./plugins` 目录下,通过在项目 `xmake.lua`中调用 `add_plugindirs("plugins")` 添加当前项目的插件搜索目录.只对当前项目生效. 3.1、或者通过`includes("xmake/**.lua")` 直接引入插件. 和 `add_plugindirs` 冲突, 二选一. > [xmake 插件开发](https://blog.dang8080.cn/xmake-docs/zh-cn/plugin/plugin_development.html)