Skip to content

Commit fe572c0

Browse files
committed
dist-apk: pack a native library that is not an ELF object as it is, with a warning
1 parent b6c9982 commit fe572c0

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

dist/apk.cppm

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2024,13 +2024,27 @@ inline plan plan_for(options opt = {}) {
20242024
{ std::error_code ec; fs::remove_all(work, ec); }
20252025
std::vector<std::string> libInputs;
20262026
// A library reaches `lib/<abi>/` stripped, as an action of its own, or
2027-
// copied as it is when the debug information is kept.
2027+
// copied as it is when the debug information is kept. A file that is not
2028+
// an ELF object -- an archive can carry anything under `jni/` -- is copied
2029+
// as it is with a warning, as the Android Gradle plugin packs a library it
2030+
// cannot strip.
2031+
const auto is_elf = [](const std::string& path) {
2032+
std::ifstream in(path, std::ios::binary);
2033+
char magic[4] = {};
2034+
return in.read(magic, 4) && magic[0] == 0x7f && magic[1] == 'E' && magic[2] == 'L' && magic[3] == 'F';
2035+
};
20282036
const auto place_library = [&](const std::string& so, const std::string& abi) {
20292037
const fs::path dst = work / "lib" / abi / fs::path(so).filename();
20302038
if (llvmStrip.empty()) {
20312039
collect_tree(so, dst, libInputs);
20322040
return;
20332041
}
2042+
if (!is_elf(so)) {
2043+
mcpp::warning(std::format(
2044+
"mcpp.dist.apk: {} is not an ELF object, so it is packed without being stripped.", so).c_str());
2045+
collect_tree(so, dst, libInputs);
2046+
return;
2047+
}
20342048
std::error_code ec;
20352049
fs::create_directories(dst.parent_path(), ec);
20362050
step strip;

0 commit comments

Comments
 (0)