Skip to content

Fix build and test with modern compilers #69

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

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
114 changes: 0 additions & 114 deletions .circleci/config.yml

This file was deleted.

26 changes: 26 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: ci

on:
push:

pull_request:
branches:
- "*"

jobs:
build:
runs-on: ubuntu-24.04

strategy:
matrix:
compiler: [clang++-16, clang++-17, clang++-18, g++-12, g++-13, g++-14]

steps:
- uses: actions/checkout@v4

- name: Build with ${{ matrix.compiler }}
env:
CXX: ${{ matrix.compiler }}
run: |
make clean
make test examples
26 changes: 21 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,29 @@ BUILD := build/$(VARIANT)
COMPILER := $(shell CXX="${CXX}" misc/compiler.sh)
COMPILER_MAJOR_VERSION := $(shell CXX="${CXX}" misc/compiler-major-version.sh)

COMMON_WARNINGS := \
-Wall \
-Wextra \
-pedantic \
-Wno-unused-but-set-variable \
-Wno-switch-default \
-Wno-cast-function-type

ifeq ($(COMPILER), clang)
CXXFLAGS_WARNINGS := -Weverything -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-exit-time-destructors
ifeq ($(shell test $(COMPILER_MAJOR_VERSION) -gt 4; echo $$?),0)
CXXFLAGS_WARNINGS += -Wno-unused-template
endif
CXXFLAGS_WARNINGS := \
$(COMMON_WARNINGS) \
-Weverything \
-Wno-c++98-compat \
-Wno-c++98-compat-pedantic \
-Wno-exit-time-destructors \
-Wno-unused-template \
-Wno-poison-system-directories \
-Wno-cast-function-type-strict \
-Wno-shadow-field \
-Wno-reserved-identifier \
-Wno-unsafe-buffer-usage
else ifeq ($(COMPILER), gcc)
CXXFLAGS_WARNINGS := -Wall -Wextra -pedantic -Wno-unused-but-set-variable
CXXFLAGS_WARNINGS := $(COMMON_WARNINGS)
endif

CXXFLAGS := $(CXXFLAGS) --std=c++14 -fPIC -Iinclude $(CXXFLAGS_WARNINGS) -Werror
Expand Down
3 changes: 1 addition & 2 deletions examples/NativePeer.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public static void main(String[] args) {
System.out.println("2 + 2 = " + calculator.add(2, 2));
System.out.println("8 - 4 = " + calculator.subtract(8, 4));

// You wouldn't normally use this; it's here to show that the native finalizer does get executed.
System.runFinalizersOnExit(true);
Copy link
Author

@louwers louwers Jun 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not available in modern Java versions.

// the native finalizer will get executed
}
}
4 changes: 2 additions & 2 deletions include/jni/native_method.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,9 @@ namespace jni
template < class Peer, class TagType, class = std::enable_if_t< std::is_same<P, Peer>::value > >
auto operator()(const Field<TagType, jlong>& field)
{
auto wrapper = [field, lambda = lambda] (JNIEnv& env, Object<TagType>& obj, Args... args)
auto wrapper = [field, currLambda = lambda] (JNIEnv& env, Object<TagType>& obj, Args... args)
{
return lambda(env, *reinterpret_cast<P*>(obj.Get(env, field)), args...);
return currLambda(env, *reinterpret_cast<P*>(obj.Get(env, field)), args...);
};

return MakeNativeMethod(name, wrapper);
Expand Down
5 changes: 5 additions & 0 deletions include/jni/string_conversion.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
#include <locale>
#include <codecvt>

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"

namespace jni
{
inline std::u16string convertUTF8ToUTF16(const std::string& string)
Expand All @@ -19,3 +22,5 @@ namespace jni
return std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t>().to_bytes(string);
}
}

#pragma GCC diagnostic pop