mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-04-22 14:41:33 +00:00
Always go through rustup proxies
This commit is contained in:
parent
8e604d2ab8
commit
1523ed9f78
20
build.py
20
build.py
@ -234,10 +234,9 @@ def build_cpp_src(targets: set):
|
|||||||
def run_cargo(cmds):
|
def run_cargo(cmds):
|
||||||
ensure_paths()
|
ensure_paths()
|
||||||
env = os.environ.copy()
|
env = os.environ.copy()
|
||||||
env["PATH"] = f'{rust_bin}{os.pathsep}{env["PATH"]}'
|
env["RUSTUP_TOOLCHAIN"] = str(rust_sysroot)
|
||||||
env["CARGO_BUILD_RUSTC"] = str(rust_bin / f"rustc{EXE_EXT}")
|
|
||||||
env["CARGO_BUILD_RUSTFLAGS"] = f"-Z threads={min(8, cpu_count)}"
|
env["CARGO_BUILD_RUSTFLAGS"] = f"-Z threads={min(8, cpu_count)}"
|
||||||
return execv([cargo, *cmds], env)
|
return execv(["cargo", *cmds], env)
|
||||||
|
|
||||||
|
|
||||||
def build_rust_src(targets: set):
|
def build_rust_src(targets: set):
|
||||||
@ -505,12 +504,10 @@ def build_all():
|
|||||||
def clippy_cli():
|
def clippy_cli():
|
||||||
args.force_out = True
|
args.force_out = True
|
||||||
os.chdir(Path("native", "src"))
|
os.chdir(Path("native", "src"))
|
||||||
cmds = ["clippy", "--no-deps"]
|
cmds = ["clippy", "--no-deps", "--target"]
|
||||||
for triple in build_abis.values():
|
for triple in build_abis.values():
|
||||||
cmds.append("--target")
|
run_cargo(cmds + [triple])
|
||||||
cmds.append(triple)
|
run_cargo(cmds + [triple, "--release"])
|
||||||
run_cargo(cmds)
|
|
||||||
run_cargo(cmds + ["--release"])
|
|
||||||
os.chdir(Path("..", ".."))
|
os.chdir(Path("..", ".."))
|
||||||
|
|
||||||
|
|
||||||
@ -653,8 +650,8 @@ def patch_avd_file():
|
|||||||
|
|
||||||
|
|
||||||
def ensure_paths():
|
def ensure_paths():
|
||||||
global sdk_path, ndk_root, ndk_path, ndk_build, rust_bin
|
global sdk_path, ndk_root, ndk_path, ndk_build, rust_sysroot
|
||||||
global llvm_bin, cargo, gradlew, adb_path, native_gen_path
|
global llvm_bin, gradlew, adb_path, native_gen_path
|
||||||
|
|
||||||
# Skip if already initialized
|
# Skip if already initialized
|
||||||
if "sdk_path" in globals():
|
if "sdk_path" in globals():
|
||||||
@ -671,11 +668,10 @@ def ensure_paths():
|
|||||||
ndk_root = sdk_path / "ndk"
|
ndk_root = sdk_path / "ndk"
|
||||||
ndk_path = ndk_root / "magisk"
|
ndk_path = ndk_root / "magisk"
|
||||||
ndk_build = ndk_path / "ndk-build"
|
ndk_build = ndk_path / "ndk-build"
|
||||||
rust_bin = ndk_path / "toolchains" / "rust" / "bin"
|
rust_sysroot = ndk_path / "toolchains" / "rust"
|
||||||
llvm_bin = (
|
llvm_bin = (
|
||||||
ndk_path / "toolchains" / "llvm" / "prebuilt" / f"{os_name}-x86_64" / "bin"
|
ndk_path / "toolchains" / "llvm" / "prebuilt" / f"{os_name}-x86_64" / "bin"
|
||||||
)
|
)
|
||||||
cargo = rust_bin / "cargo"
|
|
||||||
adb_path = sdk_path / "platform-tools" / "adb"
|
adb_path = sdk_path / "platform-tools" / "adb"
|
||||||
gradlew = Path.cwd() / "gradlew"
|
gradlew = Path.cwd() / "gradlew"
|
||||||
|
|
||||||
|
@ -40,12 +40,9 @@
|
|||||||
|
|
||||||
### Developing Rust
|
### Developing Rust
|
||||||
|
|
||||||
The Magisk NDK package [ONDK](https://github.com/topjohnwu/ondk) (the one installed with `./build.py ndk`) bundles a complete Rust toolchain, so _building_ the Magisk project itself does not require any further configuration. However, if you'd like to work on the Rust codebase with proper support, you'd need some setup as most development tools are built around `rustup`.
|
First, install [rustup](https://www.rust-lang.org/tools/install), the official Rust toolchain manager. The Magisk NDK package [ONDK](https://github.com/topjohnwu/ondk) (the one installed with `./build.py ndk`) bundles a complete Rust toolchain, so _building_ the Magisk project itself does not require any further configuration.
|
||||||
|
|
||||||
Let's first setup `rustup` to use our custom ONDK Rust toolchain by default:
|
However, if you'd like to work on the Rust codebase, it'll be easier if you link ONDK's Rust toolchain in `rustup` and set it as default so several development tools and IDEs will work properly:
|
||||||
|
|
||||||
- Install [rustup](https://rustup.rs/), the official Rust toolchain manager
|
|
||||||
- Link the ONDK Rust toolchain and set it as default:
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Link the ONDK toolchain with the name "magisk"
|
# Link the ONDK toolchain with the name "magisk"
|
||||||
@ -54,7 +51,7 @@ rustup toolchain link magisk "$ANDROID_HOME/ndk/magisk/toolchains/rust"
|
|||||||
rustup default magisk
|
rustup default magisk
|
||||||
```
|
```
|
||||||
|
|
||||||
If you plan to use VSCode, you can then install the [rust-analyzer](https://marketplace.visualstudio.com/items?itemName=rust-lang.rust-analyzer) plugin and everything should be good to go. If you plan to use Jetbrain IDEs (e.g. [Rustrover](https://www.jetbrains.com/rust/), or its Rust Plugin), due to its poor support with custom toolchains, we need some additional setup:
|
If you plan to use VSCode, you can then install the [rust-analyzer](https://marketplace.visualstudio.com/items?itemName=rust-lang.rust-analyzer) plugin and everything should be good to go. If you plan to use Jetbrain IDEs (e.g. [Rustrover](https://www.jetbrains.com/rust/), or its Rust Plugin), we need some additional setup:
|
||||||
|
|
||||||
- Install the official nightly toolchain and add some components. We won't actually use the nightly toolchain for anything other than tricking the IDE to cooperate; the magic happens in the wrapper we setup in the next step.
|
- Install the official nightly toolchain and add some components. We won't actually use the nightly toolchain for anything other than tricking the IDE to cooperate; the magic happens in the wrapper we setup in the next step.
|
||||||
|
|
||||||
|
@ -34,8 +34,12 @@ syn = "2"
|
|||||||
quote = "1"
|
quote = "1"
|
||||||
proc-macro2 = "1"
|
proc-macro2 = "1"
|
||||||
argh = { version = "0.1.13", default-features = false }
|
argh = { version = "0.1.13", default-features = false }
|
||||||
libz-rs-sys = { version = "0.4.2", default-features = false, features = ["c-allocator"] }
|
libz-rs-sys = { version = "0.4.2", default-features = false, features = [
|
||||||
libbz2-rs-sys = { version = "0.1.3", default-features = false, features = ["c-allocator"] }
|
"c-allocator",
|
||||||
|
] }
|
||||||
|
libbz2-rs-sys = { version = "0.1.3", default-features = false, features = [
|
||||||
|
"c-allocator",
|
||||||
|
] }
|
||||||
|
|
||||||
# Pin version to prevent cargo update break builds
|
# Pin version to prevent cargo update break builds
|
||||||
block-buffer = "=0.11.0-rc.3"
|
block-buffer = "=0.11.0-rc.3"
|
||||||
@ -60,4 +64,4 @@ opt-level = "z"
|
|||||||
lto = "fat"
|
lto = "fat"
|
||||||
codegen-units = 1
|
codegen-units = 1
|
||||||
panic = "abort"
|
panic = "abort"
|
||||||
strip = false
|
strip = true
|
||||||
|
Loading…
x
Reference in New Issue
Block a user