Skip to content

Commit

Permalink
GameActivity PATCH: rename C symbols that need export
Browse files Browse the repository at this point in the history
Give C symbols that need to be exported a `_C` suffix so that they can
be linked into a Rust symbol with the correct name (Since we can't
directly export from C/C++ with Rust+Cargo)

See: rust-lang/rfcs#2771
  • Loading branch information
rib committed Jul 22, 2023
1 parent 1c3c932 commit e6835e4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ static jlong initializeNativeCode_native(

readConfigurationValues(code, javaConfig);

GameActivity_onCreate(code, rawSavedState, rawSavedSize);
GameActivity_onCreate_C(code, rawSavedState, rawSavedSize);

code->gameTextInput = GameTextInput_init(env, 0);
GameTextInput_setEventCallback(code->gameTextInput,
Expand Down Expand Up @@ -1130,8 +1130,12 @@ extern "C" int GameActivity_register(JNIEnv *env) {
NELEM(g_methods));
}

// XXX: This symbol is renamed with a _C suffix and then re-exported from
// Rust because Rust/Cargo don't give us a way to directly export symbols
// from C/C++ code: https://github.com/rust-lang/rfcs/issues/2771
//
extern "C" JNIEXPORT jlong JNICALL
Java_com_google_androidgamesdk_GameActivity_initializeNativeCode(
Java_com_google_androidgamesdk_GameActivity_initializeNativeCode_C(
JNIEnv *env, jobject javaGameActivity, jstring internalDataDir,
jstring obbDir, jstring externalDataDir, jobject jAssetMgr,
jbyteArray savedState, jobject javaConfig) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ typedef void GameActivity_createFunc(GameActivity* activity, void* savedState,
* "android.app.func_name" string meta-data in your manifest to use a different
* function.
*/
extern GameActivity_createFunc GameActivity_onCreate;
extern GameActivity_createFunc GameActivity_onCreate_C;

/**
* Finish the given activity. Its finish() method will be called, causing it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -616,9 +616,12 @@ static void onContentRectChanged(GameActivity* activity, const ARect *rect) {
pthread_mutex_unlock(&android_app->mutex);
}


// XXX: This symbol is renamed with a _C suffix and then re-exported from
// Rust because Rust/Cargo don't give us a way to directly export symbols
// from C/C++ code: https://github.com/rust-lang/rfcs/issues/2771
//
JNIEXPORT
void GameActivity_onCreate(GameActivity* activity, void* savedState,
void GameActivity_onCreate_C(GameActivity* activity, void* savedState,
size_t savedStateSize) {
LOGV("Creating: %p", activity);
activity->callbacks->onDestroy = onDestroy;
Expand Down

0 comments on commit e6835e4

Please sign in to comment.