Skip to content

Commit

Permalink
llvm-builder: do not build clang by default (#168)
Browse files Browse the repository at this point in the history
We only need LLD for cross compilation. This significantly reduces the LLVM build times in a cross compilation scenario. Update the README as a drive-by.
  • Loading branch information
xermicus authored Jan 17, 2025
1 parent 06f4308 commit cec2839
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 36 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build-revive-wasm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ jobs:
- name: Build host LLVM
if: steps.cache-llvm.outputs.cache-hit != 'true'
run: |
revive-llvm build
revive-llvm build --llvm-projects lld --llvm-projects clang
- name: Build target LLVM
if: steps.cache-llvm.outputs.cache-hit != 'true'
run: |
source emsdk/emsdk_env.sh
revive-llvm --target-env emscripten build
revive-llvm --target-env emscripten build --llvm-projects lld
- run: |
rustup show
Expand Down
26 changes: 13 additions & 13 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ COPY . .

RUN make install-llvm-builder
RUN revive-llvm --target-env musl clone
RUN revive-llvm --target-env musl build
RUN revive-llvm --target-env musl build --llvm-projects lld --llvm-projects clang

FROM messense/rust-musl-cross:x86_64-musl AS resolc-builder
WORKDIR /opt/revive
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ install-llvm-builder:

install-llvm: install-llvm-builder
revive-llvm clone
revive-llvm build
revive-llvm build --llvm-projects lld --llvm-projects clang

format:
cargo fmt --all --check
Expand Down
28 changes: 18 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,37 @@ Discussion around the development is hosted on the [Polkadot Forum](https://foru

`resolc` depends on the [solc](https://github.com/ethereum/solidity) binary installed on your system.

Building from source requires a compatible LLVM build.
Download and install the `resolc` frontend executable for your platform from our [releases](https://github.com/paritytech/revive/releases).

### LLVM
## Building from source

`revive` requires a build of LLVM v18.1.8 with the RISC-V _embedded_ target, including `compiler-rt`. Use the provided [revive-llvm](crates/llvm-builder/README.md) utility to compile a compatible LLVM build locally and point `$LLVM_SYS_181_PREFIX` to the installation directory afterwards.
Building revive requires a [stable Rust installation](https://rustup.rs/) and a C++ toolchain for building [LLVM](https://github.com/llvm/llvm-project) on your system.

### The `resolc` Solidity frontend
### LLVM

To install the `resolc` Solidity frontend executable:
`revive` depends on a custom build of LLVM `v18.1.8` with the RISC-V _embedded_ target, including the `compiler-rt` builtins. Use the provided [revive-llvm](crates/llvm-builder/README.md) utility to compile a compatible LLVM build locally and point `$LLVM_SYS_181_PREFIX` to the installation afterwards.

The `Makefile` provides a shortcut target to obtain a compatible LLVM build:

```bash
# Build the host LLVM dependency with PolkaVM target support
make install-llvm
export LLVM_SYS_181_PREFIX=${PWD}/target-llvm/gnu/target-final
```

# Build the resolc frontend executable
### The `resolc` Solidity frontend

To build the `resolc` Solidity frontend executable, make sure you have obtained a compatible LLVM build using [revive-llvm](crates/llvm-builder/README.md) and did export the `LLVM_SYS_181_PREFIX` environment variable pointing to it (see [above](#LLVM)).

To install the `resolc` Solidity frontend executable:

```bash
make install-bin
resolc --version
```

### Cross-compilation to WASM
### Cross-compilation to Wasm

Cross-compile resolc.js frontend executable to Wasm for running it in a Node.js or browser environment. The `REVIVE_LLVM_TARGET_PREFIX` environment variable is used to control the target environment LLVM dependency.
Cross-compile the `resolc.js` frontend executable to Wasm for running it in a Node.js or browser environment. The `REVIVE_LLVM_TARGET_PREFIX` environment variable is used to control the target environment LLVM dependency.

```bash
# Build the host LLVM dependency with PolkaVM target support
Expand All @@ -49,7 +57,7 @@ export LLVM_SYS_181_PREFIX=${PWD}/target-llvm/gnu/target-final
# Build the target LLVM dependency with PolkaVM target support
revive-llvm --target-env emscripten clone
source emsdk/emsdk_env.sh
revive-llvm --target-env emscripten build
revive-llvm --target-env emscripten build --llvm-projects lld
export REVIVE_LLVM_TARGET_PREFIX=${PWD}/target-llvm/emscripten/target-final

# Build the resolc frontend executable
Expand Down
2 changes: 1 addition & 1 deletion crates/llvm-builder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ path = "src/revive_llvm/main.rs"
doctest = false

[dependencies]
clap = { workspace = true, features = ["std", "derive"] }
clap = { workspace = true, features = ["help", "std", "derive"] }
anyhow = { workspace = true }
serde = { workspace = true, features = [ "derive" ] }
toml = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion crates/llvm-builder/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ Obtain a compatible build for your host platform from the release section of thi

```shell
revive-llvm clone
revive-llvm build
revive-llvm build --llvm-projects lld --llvm-projects clang
```

Build artifacts end up in the `./target-llvm/gnu/target-final/` directory by default.
Expand Down
8 changes: 1 addition & 7 deletions crates/llvm-builder/src/revive_llvm/arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,7 @@ pub enum Subcommand {
targets: Vec<String>,

/// LLVM projects to build LLVM with.
#[arg(
long,
default_values_t = vec![
revive_llvm_builder::llvm_project::LLVMProject::CLANG,
revive_llvm_builder::llvm_project::LLVMProject::LLD
]
)]
#[arg(long)]
llvm_projects: Vec<revive_llvm_builder::llvm_project::LLVMProject>,

/// Whether to build LLVM with run-time type information (RTTI) enabled.
Expand Down

0 comments on commit cec2839

Please sign in to comment.