Skip to content

vivo/RustAdBlockWrapper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RustAdBlockWrapper

The interface layer dependent on AdBlock 8.0 can be fully integrated with Chromium using the Chromium GN build tool which can apply chromium browser with Rust Ad Block ability.

What is?

To enhance the ad-blocking capabilities of the Chromium browser,this project proposes integrating the open-source ad-blocking library Brave's adblock-rustdeveloped by Brave, with the existing Chromium browser. This integration will enable the modified browser to support standard open-source rules for ad blocking.

Getting started

By leveraging Google’s Rust compilation tools and integrating them with the GN build method, the Rust-based AdBlock is fully merged into the Chromium browser, enabling Rust-powered ad-blocking capabilities. Edit the BUILD.gn file to include it as a project dependency. Assumed you have the chromium project source code and in the folder "src", let us get start to compile the rust ad block int chromium.

Directory structure

RustAdBlockWrapper/
├── src/                    # Main source code directory
│   ├── rs/                 # Directory containing interfaces and build scripts
│   │   ├── src/            # Interface layer and utility classes for integrating the open-source Rust ad-blocking component
│   │   ├── BUILD.gn        # Build script for files under src/ and related dependencies
│   ├── BUILD.gn            # Project-level BUILD.gn file; if other files exist at the same level as rs/, they must be registered here
└── README.md               # Project Introduction

Key Functionality

src/BUILD.gn File Responsibilities
  • Defines the module's external visibility
  • Required for using the interface layer in the Chromium browser to call Rust-related methods
  • Must specify visibility of the rs module to other modules using the visibility attribute
Terminology
  • BUILD.gn: Chromium's build configuration file (GN = Generate Ninja)
  • Visibility: Controls which other GN targets can depend on this module
  • Interface layer: Acts as a bridge between Chromium (C++) and Rust code

How to use?

Add third party rust lib for chromium

To introduce additional third-party libraries into Chromium, refer to Chromium's Automated Third-Party Rust Library Integration,Chromium will automatically generate the required GN build files for these imported libraries.

Chromium has a single set of centrally-managed direct crate dependencies. These are managed through a single Cargo.toml.In this project, we use Rust Ad Block, so we need add third party depend on key word "dependencies" in Cargo.toml .

[dependencies.adblock]
default-features = false
version = "0.8.12"

Because the adblock depend other module, we also need to add them to Cargo.toml.In additional, some rust crate module is define as test, if we want to use these modules, we need to modify the modules group in gnrt_config.toml.

[crate.adblock]
group = 'safe'

If config has been modified , use chromium's rust tools chain to download related rust lib.

vpython3 tools/crates/run_gnrt.py -- vendor   # download the crate in the Cargo.toml

After the command, the rust lib will be download in path.

Generating gn Build Rules

As we know, GN is the main compilation method for chromium, so we need to generate the GN for third patry rust lib

vpython3 tools/crates/run_gnrt.py -- gen

After this step, you can find BUILD.gn about rust lib in path.

Import gn for our interface project

Now we have the gn about the rust ad block, which we need to do is add the name of this gn in our interface project(rs/BUILD.gn)

  deps = [
    "//third_party/rust/adblock/v0_8:lib",
  ]

In this way, you can define your own class and function in "rs" folder and organize them as lib which can refer for other modules in chromium.

Compile the rust lib with chromium

The final step is import the gn at modules which you want to use ,such as android webview、content and so on.For example, in the android webview module gn, you can import the rust interface lib with dependence.

deps = [
    "YouPath/adblock:rust_lib",
]

Precautions

Version compatibility

RustAdBlockWrapper interface for using in chromium is based on rust ad block 8.1.2, chromium version is on 123. Other rust libs' version is managed by chromium tool chains.

License

We strictly adhere to the MPL 2.0 open-source license of the RustAdBlock library and have made no modifications to its source code. This project aims to build an interface layer to integrate Rust-based ad-blocking capabilities into the Chromium project.

Issue

If you get a problem in compile the project for chromium, you can raise questions in Issue.

About

Vivo browser implements ad blocking capabilities based on Rust language

Topics

Resources

License

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages