Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build libarchive with cmake if it can't be found #948

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
apt:
packages:
- ninja-build
- libarchive-dev
- cmake
install:
- source ~/virtualenv/python3.6/bin/activate
- pip install meson
Expand All @@ -32,7 +32,7 @@ jobs:
packages:
- ninja
- llvm
- libarchive
- cmake
update: true
script:
- xcodebuild -project iSH.xcodeproj -scheme iSH -sdk iphoneos CODE_SIGNING_ALLOWED=NO
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ You'll need these things to build the project:
- Meson (`pip install meson`)
- Clang and LLD (on mac, `brew install llvm`, on linux, `sudo apt install clang lld` or `sudo pacman -S clang lld` or whatever)
- sqlite3 (this is so common it may already be installed on linux and is definitely already installed on mac. if not, do something like `sudo apt install libsqlite3-dev`)
- libarchive (`brew install libarchive`, `sudo port install libarchive`, `sudo apt install libarchive-dev`) TODO: bundle this dependency
- Either libarchive (from your package manager) or cmake (to build a bundled libarchive)

## Build for iOS

Expand All @@ -41,7 +41,7 @@ Open the project in Xcode, open iSH.xcconfig, and change `ROOT_BUNDLE_IDENTIFIER

To set up your environment, cd to the project and run `meson build` to create a build directory in `build`. Then cd to the build directory and run `ninja`.

To set up a self-contained Alpine linux filesystem, download the Alpine minirootfs tarball for i386 from the [Alpine website](https://alpinelinux.org/downloads/) and run `./tools/fakefsify`, with the minirootfs tarball as the first argument and the name of the output directory as the second argument. Then you can run things inside the Alpine filesystem with `./ish -f alpine /bin/login -f root`, assuming the output directory is called `alpine`. If `tools/fakefsify` doesn't exist for you in your build directory, that might be because it couldn't find libarchive on your system (see above for ways to install it.)
To set up a self-contained Alpine linux filesystem, download the Alpine minirootfs tarball for i386 from the [Alpine website](https://alpinelinux.org/downloads/) and run `./tools/fakefsify`, with the minirootfs tarball as the first argument and the name of the output directory as the second argument. Then you can run things inside the Alpine filesystem with `./ish -f alpine /bin/login -f root`, assuming the output directory is called `alpine`. If `tools/fakefsify` doesn't exist for you in your build directory, you probably need to install libarchive or cmake (see above)

You can replace `ish` with `tools/ptraceomatic` to run the program in a real process and single step and compare the registers at each step. I use it for debugging. Requires 64-bit Linux 4.11 or later.

Expand Down
14 changes: 14 additions & 0 deletions deps/script/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
libarchive = dependency('libarchive', method: 'pkg-config', required: false)
if not libarchive.found()
# try homebrew
libarchive_lib = cc.find_library('libarchive', dirs: ['/usr/local/opt/libarchive/lib'], required: false)
if libarchive_lib.found()
libarchive = declare_dependency(dependencies: [libarchive_lib], include_directories: include_directories(['/usr/local/opt/libarchive/include']))
endif
endif
if not libarchive.found()
warning('no system libarchive found, building with cmake')
cmake = import('cmake')
libarchive = cmake.subproject('libarchive').dependency('archive_static')
endif

4 changes: 3 additions & 1 deletion meson.build
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
project('ish', 'c',
default_options: ['default_library=static', 'c_std=gnu11', 'warning_level=2'])
default_options: ['default_library=static', 'c_std=gnu11', 'warning_level=2'],
subproject_dir: 'deps')
cc = meson.get_compiler('c')

if cc.get_id() == 'clang'
Expand Down Expand Up @@ -34,6 +35,7 @@ threads = dependency('threads')
librt = cc.find_library('rt', required: false)
libm = cc.find_library('m', required: false)
sqlite3 = cc.find_library('sqlite3')
subdir('deps/script')

dependencies = [librt, libm, threads, sqlite3]

Expand Down
21 changes: 5 additions & 16 deletions tools/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,8 @@ if unicorn.found()
configure_file(input: 'ptraceomatic-gdb.gdb', output: 'unicornomatic-gdb.gdb', copy: true)
endif

libarchive = dependency('libarchive', required: false)
if not libarchive.found()
# homebrew
libarchive_lib = cc.find_library('libarchive', dirs: ['/usr/local/opt/libarchive/lib'], required: false)
if libarchive_lib.found()
libarchive = declare_dependency(dependencies: [libarchive_lib], include_directories: include_directories(['/usr/local/opt/libarchive/include']))
endif
endif

if libarchive.found()
fakefsify = executable('fakefsify', ['fakefsify.c', 'fakefs.c'], dependencies: [ish, libarchive])
custom_target('unfakefsify',
build_by_default: true,
command: ['ln', '-sf', 'fakefsify', '@OUTPUT@'],
output: 'unfakefsify')
endif
fakefsify = executable('fakefsify', ['fakefsify.c', 'fakefs.c'], dependencies: [ish, libarchive])
custom_target('unfakefsify',
build_by_default: true,
command: ['ln', '-sf', 'fakefsify', '@OUTPUT@'],
output: 'unfakefsify')