一. ndk生成交叉编译工具链
请参考:Cargo+Ndk实现Android平台的rust源码交叉编译_u011376563的博客-CSDN博客
的3.1~3.2部分内容
二. 下载libfuse3.10.0源码
youthful@youthful-VirtualBox-Ubuntu:~/test$ git clone https://github.com/libfuse/libfuse.git
注意:本文编译的是3.10.0源码,libfuse源码可能已经更新版本,请下载之后切换到release 3.10.0版本。
三. 下载新版本meson编译工具
libfuse3.10.0默认使用meson+ninja编译源码,所以需要安装这2个编译工具。
meson需要使用0.54及以上版本,直接在github上下载即可:
youthful@youthful-VirtualBox-Ubuntu:~$ mkdir ~/work/meson/
youthful@youthful-VirtualBox-Ubuntu:~$ cd ~/work/meson/
youthful@youthful-VirtualBox-Ubuntu:~/work/meson$ git clone https://github.com/mesonbuild/meson.git
下载之后的meson是一个py脚本:~/work/meson/meson/meson.py,后续交叉编译需要使用该脚本工具。
四. 下载ninja编译工具
youthful@youthful-VirtualBox-Ubuntu:~/work/meson$ sudo apt install ninja-build
五. 修改libfuse源码及配置
5.1. 为meson添加交叉编译配置文件arm64.txt
在libfuse工程根目录创建arm64.txt,该文件用于配置交叉编译工具链及库路径:
[binaries]
c = '<your_toolchain_path_prefix>/bin/aarch64-linux-android30-clang'
cpp = '<your_toolchain_path_prefix>/bin/aarch64-linux-android30-clang++'
ar = '<your_toolchain_path_prefix>/bin/aarch64-linux-android-ar'
strip = '<your_toolchain_path_prefix>/bin/aarch64-linux-android-strip'
ld = '<your_toolchain_path_prefix>bin/aarch64-linux-android-ld.gold'
[properties]
skip_sanity_check = true
sys_root = '<your_toolchain_path_prefix>/sysroot'
c_args = ['-L<your_toolchain_path_prefix>/sysroot/usr/lib/aarch64-linux-android/30']
[host_machine]
system = 'linux'
cpu_family = 'aarch64'
cpu = 'aarch64'
endian = 'little'
[target_machine]
system = 'linux'
cpu_family = 'aarch64'
cpu = 'armv8a'
endian = 'little'
其中,
<your_toolchain_path_prefix>替换为你前面保存ndk生成的交叉工具链的目录,本文为:
/home/work/ndk_standalone_21.4.7075529/arm64
5.2. 修改源码及配置
1)删除example/meson.build,因为不需要示例
2)修改lib/fuse.c:
youthful@youthful-VirtualBox-Ubuntu:~/work/fuse/libfuse-3.10$ git diff lib/fuse.c
diff --git a/lib/fuse.c b/lib/fuse.c
index 91a4b70..202d212 100644
--- a/lib/fuse.c
+++ b/lib/fuse.c
@@ -4876,6 +4876,9 @@ void fuse_stop_cleanup_thread(struct fuse *f)
}
}
+int pthread_cancel(pthread_t thread) {
+ return pthread_kill(thread, SIGUSR1);
+}
3)修改lib/fuse_loop_mt.c:
youthful@youthful-VirtualBox-Ubuntu:~/work/fuse/libfuse-3.10$ git diff lib/fuse_loop_mt.c
diff --git a/lib/fuse_loop_mt.c b/lib/fuse_loop_mt.c
index 8fcc46c..ba303a8 100644
--- a/lib/fuse_loop_mt.c
+++ b/lib/fuse_loop_mt.c
@@ -28,6 +28,23 @@
/* Environment var controlling the thread stack size */
#define ENVNAME_THREAD_STACK "FUSE_THREAD_STACK"
+#define PTHREAD_CANCEL_ENABLE 1
+#define PTHREAD_CANCEL_DISABLE 0
+
+static int pthread_setcancelstate(int state, int *oldstate) {
+ sigset_t new, old;
+ int ret;
+ sigemptyset (&new);
+ sigaddset (&new, SIGUSR1);
+
+ ret = pthread_sigmask(state == PTHREAD_CANCEL_ENABLE ? SIG_BLOCK : SIG_UNBLOCK, &new , &old);
+ if(oldstate != NULL)
+ {
+ *oldstate =sigismember(&old, SIGUSR1) == 0 ? PTHREAD_CANCEL_DISABLE : PTHREAD_CANCEL_ENABLE;
+ }
+ return ret;
+}
+
struct fuse_worker {
4)修改lib/meson.build
youthful@youthful-VirtualBox-Ubuntu:~/work/fuse/libfuse-3.10$ git diff lib/meson.build
diff --git a/lib/meson.build b/lib/meson.build
index 98461d8..bc95589 100644
--- a/lib/meson.build
+++ b/lib/meson.build
@@ -10,31 +10,42 @@ else
libfuse_sources += [ 'mount_bsd.c' ]
endif
-deps = [ thread_dep ]
-if cfg.get('HAVE_ICONV')
- libfuse_sources += [ 'modules/iconv.c' ]
- libiconv = cc.find_library('iconv', required: false)
- if libiconv.found()
- deps += [ libiconv ]
- endif
-endif
+# deps = [ thread_dep ]
+# if cfg.get('HAVE_ICONV')
+# libfuse_sources += [ 'modules/iconv.c' ]
+# libiconv = cc.find_library('iconv', required: false)
+# if libiconv.found()
+# deps += [ libiconv ]
+# endif
+# endif
+
+deps = []
libdl = cc.find_library('dl', required: false)
if libdl.found()
deps += [ libdl ]
endif
-if host_machine.system().startswith('netbsd')
- deps += [ cc.find_library('perfuse'),
- cc.find_library('puffs') ]
-else
- # Required for clock_gettime before glibc 2.17
- deps += cc.find_library('rt')
-endif
+# if host_machine.system().startswith('netbsd')
+# deps += [ cc.find_library('perfuse'),
+# cc.find_library('puffs') ]
+# else
+# # Required for clock_gettime before glibc 2.17
+# deps += cc.find_library('rt')
+# endif
fusermount_path = join_paths(get_option('prefix'), get_option('bindir'))
-libfuse = library('fuse3', libfuse_sources, version: meson.project_version(),
- soversion: '3', include_directories: include_dirs,
+# libfuse = library('fuse3', libfuse_sources, version: meson.project_version(),
+# soversion: '3', include_directories: include_dirs,
+# dependencies: deps, install: true,
+# link_depends: 'fuse_versionscript',
+# c_args: [ '-DFUSE_USE_VERSION=35',
+# '-DFUSERMOUNT_DIR="@0@"'.format(fusermount_path) ],
+# link_args: ['-Wl,--version-script,' + meson.current_source_dir()
+# + '/fuse_versionscript' ])
+
+libfuse = static_library('fuse3', libfuse_sources,
+ include_directories: include_dirs,
dependencies: deps, install: true,
link_depends: 'fuse_versionscript',
c_args: [ '-DFUSE_USE_VERSION=35',
@@ -42,13 +53,13 @@ libfuse = library('fuse3', libfuse_sources, version: meson.project_version(),
link_args: ['-Wl,--version-script,' + meson.current_source_dir()
+ '/fuse_versionscript' ])
-pkg = import('pkgconfig')
-pkg.generate(libraries: [ libfuse, '-lpthread' ],
- libraries_private: '-ldl',
- version: meson.project_version(),
- name: 'fuse3',
- description: 'Filesystem in Userspace',
- subdirs: 'fuse3')
+# pkg = import('pkgconfig')
+# pkg.generate(libraries: [ libfuse, '-lpthread' ],
+# libraries_private: '-ldl',
+# version: meson.project_version(),
+# name: 'fuse3',
+# description: 'Filesystem in Userspace',
+# subdirs: 'fuse3')
libfuse_dep = declare_dependency(include_directories: include_dirs,
5)meson.build
youthful@youthful-VirtualBox-Ubuntu:~/work/fuse/libfuse-3.10$ git diff meson.build
diff --git a/meson.build b/meson.build
index 8a6587b..135d110 100644
--- a/meson.build
+++ b/meson.build
@@ -47,8 +47,8 @@ foreach func : test_funcs
endforeach
cfg.set('HAVE_SETXATTR',
cc.has_function('setxattr', prefix: '#include <sys/xattr.h>'))
-cfg.set('HAVE_ICONV',
- cc.has_function('iconv', prefix: '#include <iconv.h>'))
+# cfg.set('HAVE_ICONV',
+# cc.has_function('iconv', prefix: '#include <iconv.h>'))
# Test if structs have specific member
cfg.set('HAVE_STRUCT_STAT_ST_ATIM',
@@ -118,7 +118,7 @@ endif
include_dirs = include_directories('include', 'lib', '.')
# Common dependencies
-thread_dep = dependency('threads')
+# thread_dep = dependency('threads')
#
# Read build files from sub-directories
@@ -128,13 +128,13 @@ if get_option('utils') and not platform.endswith('bsd') and platform != 'dragonf
subdirs += [ 'util', 'doc' ]
endif
-if get_option('examples')
- subdirs += 'example'
-endif
+# if get_option('examples')
+# subdirs += 'example'
+# endif
-if get_option('tests')
- subdirs += 'test'
-endif
+# if get_option('tests')
+# subdirs += 'test'
+# endif
foreach n : subdirs
6)util/meson.build
youthful@youthful-VirtualBox-Ubuntu:~/work/fuse/libfuse-3.10$ git diff util/meson.build
diff --git a/util/meson.build b/util/meson.build
index 577668f..7e2a256 100644
--- a/util/meson.build
+++ b/util/meson.build
@@ -14,16 +14,16 @@ executable('mount.fuse3', ['mount.fuse.c'],
c_args: '-DFUSE_USE_VERSION=35')
-udevrulesdir = get_option('udevrulesdir')
-if udevrulesdir == ''
- udev = dependency('udev')
- udevrulesdir = join_paths(udev.get_pkgconfig_variable('udevdir'), 'rules.d')
-endif
+# udevrulesdir = get_option('udevrulesdir')
+# if udevrulesdir == ''
+# udev = dependency('udev')
+# udevrulesdir = join_paths(udev.get_pkgconfig_variable('udevdir'), 'rules.d')
+# endif
-meson.add_install_script('install_helper.sh',
- join_paths(get_option('prefix'), get_option('sysconfdir')),
- join_paths(get_option('prefix'), get_option('bindir')),
- udevrulesdir,
- '@0@'.format(get_option('useroot')))
+# meson.add_install_script('install_helper.sh',
+# join_paths(get_option('prefix'), get_option('sysconfdir')),
+# join_paths(get_option('prefix'), get_option('bindir')),
+# udevrulesdir,
+# '@0@'.format(get_option('useroot')))
六. 编译libfuse源码
youthful@youthful-VirtualBox-Ubuntu:~/work/fuse/libfuse-3.10$ ~/work/meson/meson/meson.py arm64-build --cross-file ./arm64.txt
youthful@youthful-VirtualBox-Ubuntu:~/work/fuse/libfuse-3.10$ ninja -C arm64-build
编译结果(<project_root>:libfuse源码根目录):
<project_root>/arm64-build/lib/libfuse3.a(注:如果要编译so,请在5.4步骤修改lib/meson.build时,将library()字段放开,并注释掉static_library()字段!!!)
<project_root>/arm64-build/util/fusermount3
<project_root>/arm64-build/util/mount.fuse3
七. 使用方法
当其他库需要依赖libfuse3.a,请指定libfuse3.a所在路径。
运行时:
1)如果是编译的libfuse3.so.*,需要将该so通过adb push到/system/lib64/目录下;
2)将fusermount3和mount.fuse3通过adb push到/system/bin/目录下。
|