Skip to content

Commit

Permalink
[Docs] Using LLVM from the absolute path
Browse files Browse the repository at this point in the history
  • Loading branch information
sbogolepov committed Sep 24, 2020
1 parent c409192 commit c6e6e28
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
16 changes: 15 additions & 1 deletion BUILDING_LLVM.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,32 @@ After these steps `clang-llvm-apple-8.0.0-darwin-macos` directory will contain L

## Part 2. Building Kotlin/Native against given LLVM distribution.

By default, Kotlin/Native will try to download LLVM distribution from CDN if it is not present in `$HOME/.konan/dependencies` folder.
By default, Kotlin/Native will try to download LLVM distribution from CDN if it is not present in `$HOME/.konan/dependencies` folder.
There are two ways to bypass this behaviour.

#### Option A. Substitute prebuilt distribution.
This option doesn't require you to edit compiler sources, but a bit harder.

The compiler checks dependency presence by reading contents of `$HOME/.konan/dependencies/.extracted` file.
So to avoid LLVM downloading, we should manually add a record to the `.extracted` file:
1. Create `$HOME/.konan/dependencies/.extracted` file if it is not created.
2. Add `clang-llvm-apple-8.0.0-darwin-macos` line.

and put `clang-llvm-apple-8.0.0-darwin-macos` directory from the Part 1 to `$HOME/.konan/dependencies/`.

#### Option B. Provide an absolute path to the distribution.
This option requires user to edit [konan.properties file](konan/konan.properties).
Set `llvmHome.<HOST_NAME>` to an absolute path to your LLVM distribution and
set `llvmVersion.<HOST_NAME>` to its version.
For example, provide a path to `clang-llvm-apple-8.0.0-darwin-macos` from the Part 1 and set version to 8.0.0.

Now we are ready to build Kotlin/Native itself. The process is described in [README.md](README.md).
Please note that we still need to run `./gradlew dependencies:update` to download other dependencies (e.g. libffi).

## Q&A

— Can I override `.konan` location?
— Yes, by setting `$KONAN_DATA_DIR` environment variable. See [HACKING.md](HACKING.md#compiler-environment-variables).

- Can I use another LLVM distribution without rebuilding Kotlin/Native?
- Yes, see [HACKING.md](HACKING.md#using-different-llvm-distributions-as-part-of-kotlinnative-compilation-pipeline).
12 changes: 11 additions & 1 deletion HACKING.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,19 @@ $ ./gradlew backend.native:tests:runExternal -Ptest_two_stage=true 2>&1 | tee lo

## LLVM

See [BUILDING_LLVM.md](BUILDING_LLVM.md) if you want to use your own LLVM distribution
See [BUILDING_LLVM.md](BUILDING_LLVM.md) if you want to build and use your own LLVM distribution
instead of provided one.

### Using different LLVM distributions as part of Kotlin/Native compilation pipeline.

`llvmHome.<HOST_NAME>` variable in `<distribution_location>/konan/konan.properties` controls
which LLVM distribution Kotlin/Native will use in its compilation pipeline.
You can replace its value with either `$llvm.<HOST_NAME>.{dev, user}` to use one of predefined distributions
or pass an absolute to your own distribution.
Don't forget to set `llvmVersion.<HOST_NAME>` to the version of your LLVM distribution.

### Playing with compilation pipeline.

Following compiler phases control different parts of LLVM pipeline:
1. `LinkBitcodeDependencies`. Linkage of produced bitcode with runtime and some other dependencies.
2. `BitcodeOptimization`. Running LLVM optimization pipeline.
Expand Down

0 comments on commit c6e6e28

Please sign in to comment.