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

Add objective-c and java to clang-format #3154

Merged
merged 2 commits into from
Jan 20, 2025
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/formatting.yaml
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ jobs:
- uses: DoozyX/clang-format-lint-action@v0.14
with:
source: '.'
extensions: 'h,c,cc,proto'
extensions: 'h,c,cc,proto,java,m'
clangFormatVersion: 14
- uses: actionsx/prettier@v2
with:
21 changes: 11 additions & 10 deletions examples/android/AndroidMain.java
Original file line number Diff line number Diff line change
@@ -6,16 +6,17 @@
import android.widget.TextView;

public class AndroidMain extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.android_main);
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.android_main);

Log.v("Bazel", "Android app launched");
System.loadLibrary("android_app"); // 'android_app' is the name of the native library in this example
Log.v("Bazel", "Value from rust: " + JniShim.getValue());
Log.v("Bazel", "Android app launched");
System.loadLibrary(
"android_app"); // 'android_app' is the name of the native library in this example
Log.v("Bazel", "Value from rust: " + JniShim.getValue());

final TextView helloTextView = (TextView) findViewById(R.id.text_view);
helloTextView.setText("Value from rust: " + JniShim.getValue());
}
final TextView helloTextView = (TextView) findViewById(R.id.text_view);
helloTextView.setText("Value from rust: " + JniShim.getValue());
}
}
2 changes: 1 addition & 1 deletion examples/android/JniShim.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package com.example.androidapp;

public class JniShim {
public static native int getValue();
public static native int getValue();
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.example.rustjni;

import org.junit.Test;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;

import org.junit.Test;

public class RustJniTest {
@Test
public void testCallsJniToRust() throws Exception {
Original file line number Diff line number Diff line change
@@ -2,10 +2,8 @@

import com.google.devtools.build.runfiles.AutoBazelRepository;
import com.google.devtools.build.runfiles.Runfiles;

import com.sun.jna.Library;
import com.sun.jna.Native;

import java.io.IOException;

@AutoBazelRepository
@@ -22,7 +20,9 @@ static RustStringLength loadNativeLibrary() throws IOException {
extension = "dll";
}
Runfiles.Preloaded runfiles = Runfiles.preload();
String dylibPath = runfiles.withSourceRepository(AutoBazelRepository_RustStringLength.NAME).rlocation("rules_rust_example_ffi/java_calling_rust/rust-crate/" + prefix + "rstrlen." + extension);
String dylibPath = runfiles.withSourceRepository(AutoBazelRepository_RustStringLength.NAME)
.rlocation("rules_rust_example_ffi/java_calling_rust/rust-crate/"
+ prefix + "rstrlen." + extension);

return Native.load(dylibPath, RustStringLength.class);
}
6 changes: 3 additions & 3 deletions examples/ios/main_lib.m
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
extern void print_something_from_rust(void);

int main() {
print_something_from_rust();
printf("Some value from rust: %d\n", get_a_value_from_rust());
return 0;
print_something_from_rust();
printf("Some value from rust: %d\n", get_a_value_from_rust());
return 0;
}