Giter VIP home page Giter VIP logo

Comments (3)

ahumesky avatar ahumesky commented on June 26, 2024 1

It's unlikely that we'll add this directly to the android rules, but it might be possible to do this through a genrule or some additional starlark.

A basic example:

WORKSPACE:

android_sdk_repository(name = "androidsdk")

BUILD:

genrule(
  name = "aidl_rust",
  srcs = ["com/example/android/IRemoteService.aidl"],
  outs = ["com/example/android/IRemoteService.rs"],
  tools = ["@androidsdk//:aidl_binary"],
  cmd = "$(location @androidsdk//:aidl_binary) --lang=rust $< --out $(GENDIR)",
)

com/example/android/IRemoteService.aidl:

// IRemoteService.aidl
package com.example.android;

// Declare any non-default types here with import statements

/** Example service interface */
interface IRemoteService {
    /** Request the process ID of this service, to do evil things with it. */
    int getPid();

    /**
     * Demonstrates some basic types that you can use as parameters
     * and return values in AIDL.
     */
    void basicTypes(int anInt, long aLong, boolean aBoolean, float aFloat,
            double aDouble, String aString);
}
$ bazel build aidl_rust
INFO: Analyzed target //:aidl_rust (72 packages loaded, 331 targets configured).
INFO: Found 1 target...
Target //:aidl_rust up-to-date:
  bazel-bin/com/example/android/IRemoteService.rs
INFO: Elapsed time: 0.560s, Critical Path: 0.02s
INFO: 7 processes: 5 internal, 2 linux-sandbox.
INFO: Build completed successfully, 7 total actions

Some additional poking around:

This is where aidl_interface is implemented in Soong:

https://cs.android.com/android/platform/superproject/main/+/main:system/tools/aidl/build/aidl_interface.go;drc=5c3d46d304ce279646c9649d4c6a76f21b71cfbf

here's a bazel equivalent of aidl_interface in Android Platform:
https://cs.android.com/android/platform/superproject/main/+/main:build/bazel/rules/aidl/aidl_interface.bzl;l=95;drc=17861480bfd6af30fdf77c44b134664e03f164e7

but notably rust support is not there:
https://cs.android.com/android/platform/superproject/main/+/main:build/bazel/rules/aidl/aidl_interface.bzl;l=22;drc=17861480bfd6af30fdf77c44b134664e03f164e7

this appears to be the invocation of aidl for rust:
https://cs.android.com/android/platform/superproject/main/+/main:system/tools/aidl/build/aidl_gen_rule.go;l=65;drc=5c3d46d304ce279646c9649d4c6a76f21b71cfbf

There's this additional "aidl rust glue":
https://cs.android.com/android/platform/superproject/main/+/main:system/tools/aidl/build/aidl_rust_glue.py;drc=d8a838aec6662e409106ddc6ca128e1bd3b3b8c9

some comments about it here:
https://cs.android.com/android/platform/superproject/main/+/main:system/tools/aidl/build/aidl_rust_source_provider.go;l=69-76;drc=bee38ebf2b27015f05e5e34d21fc7e4b33a10333

from rules_android.

geaden avatar geaden commented on June 26, 2024

@ahumesky Thanks! I'll give it a try

from rules_android.

geaden avatar geaden commented on June 26, 2024

I've given it a try and it works perfect! One thing to notice:

$(GENDIR) worked only if I put my genrule in the workspace root BUILD.bazel.

For other cases (if my *.aidl resides in let's say //src/birthdayservice/aidl/com/example/birthdayservice/IBirthdayService.aidl) I used $(RULEDIR) instead.

I'm closing the issue. Thanks again @ahumesky for the detailed response!

from rules_android.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.