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

Import a subset of libbase, build an AAR. #1062

Merged
merged 1 commit into from
Jun 11, 2024
Merged
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 base/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
32 changes: 32 additions & 0 deletions base/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
plugins {
id("ndksamples.android.library")
}

android {
namespace = "com.android.ndk.samples.base"

externalNativeBuild {
cmake {
path = file("src/main/cpp/CMakeLists.txt")
}
}

buildFeatures {
prefabPublishing = true
}

prefab {
create("base") {
headers = "src/main/cpp/include"
}
}
}

dependencies {

implementation(libs.appcompat)
implementation(libs.material)
testImplementation(libs.junit)
androidTestImplementation(libs.ext.junit)
androidTestImplementation(libs.espresso.core)
}
14 changes: 14 additions & 0 deletions base/src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
cmake_minimum_required(VERSION 3.22.1)
project(Base LANGUAGES CXX)

add_compile_options(-Wall -Werror -Wextra)

add_library(base
STATIC
logging.cpp
)

target_compile_features(base PRIVATE cxx_std_23)
target_compile_options(base PRIVATE -Wno-vla-cxx-extension)
target_include_directories(base PUBLIC include)
target_link_libraries(base PUBLIC log)
39 changes: 39 additions & 0 deletions base/src/main/cpp/include/base/errno_restorer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (C) 2020 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#pragma once

#include <errno.h>

namespace ndksamples::base {

class ErrnoRestorer {
public:
ErrnoRestorer() : saved_errno_(errno) {}
ErrnoRestorer(const ErrnoRestorer&) = delete;

~ErrnoRestorer() { errno = saved_errno_; }

ErrnoRestorer& operator=(const ErrnoRestorer&) = delete;

// Allow this object to be used as part of && operation.
explicit operator bool() const { return true; }

private:
const int saved_errno_;
};

} // namespace ndksamples::base
Loading
Loading