# How to use locally built LLVM to build Julia?

**URL:** <https://discourse.julialang.org/t/how-to-use-locally-built-llvm-to-build-julia/96660>\
**Category:** Internals & Design\
**Tags:** question\
**Created:** [March 27, 2023, 1:11pm UTC](https://discourse.julialang.org/t/how-to-use-locally-built-llvm-to-build-julia/96660 "2023-03-27T13:11:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ahsan](https://avatars.discourse-cdn.com/v4/letter/a/958977/32.png) [@ahsan](https://discourse.julialang.org/u/ahsan)\
**Post date:** [March 27, 2023, 1:11pm UTC](https://discourse.julialang.org/t/how-to-use-locally-built-llvm-to-build-julia/96660/1 "2023-03-27T13:11:21Z")

</div>

I was wondering how could one use a locally built LLVM (with some bug fixes) to build Julia? Is there some document that outlines this.  
Thanks!

---

<div class="post-metadata">

**Author:** ![vchuravy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vchuravy/32/8_2.png) [@vchuravy](https://discourse.julialang.org/u/vchuravy)\
**Post date:** [March 31, 2023, 5:08pm UTC](https://discourse.julialang.org/t/how-to-use-locally-built-llvm-to-build-julia/96660/2 "2023-03-31T17:08:07Z")

</div>

Setting in my Make.user:

```julia
vchuravy@odin ~/b/julia-llvmgit> cat Make.user
DEPS_GIT=1
USE_BINARYBUILDER_LLVM=0

```

when I then `make -C deps get-llvm`

```julia
vchuravy@odin ~/b/julia-llvmgit> make -C deps get-llvm
make: Entering directory '/home/vchuravy/builds/julia-llvmgit/deps'
git clone -q --mirror --branch julia-14.0.6-2 https://github.com/JuliaLang/llvm-project.git /home/vchuravy/src/julia/deps/srccache/llvm.git/
touch -c /home/vchuravy/src/julia/deps/srccache/llvm.git
make: Leaving directory '/home/vchuravy/builds/julia-llvmgit/deps'

```

I now have bare checkout in `/home/vchuravy/src/julia/deps/srccache/llvm.git/`.

Using `make -C deps extract-llvm` I can convert that bare checkout into a full one

```julia
vchuravy@odin ~/b/julia-llvmgit> make -C deps extract-llvm
make: Entering directory '/home/vchuravy/builds/julia-llvmgit/deps'
# try to update the cache, if that fails, attempt to continue anyways (the ref might already be local)
cd /home/vchuravy/src/julia/deps/srccache/llvm.git && git fetch -q https://github.com/JuliaLang/llvm-project.git julia-14.0.6-2:remotes/origin/julia-14.0.6-2
git clone -q --depth=10 --branch julia-14.0.6-2 /home/vchuravy/src/julia/deps/srccache/llvm.git /home/vchuravy/src/julia/deps/srccache/llvm
warning: --depth is ignored in local clones; use file:// instead.
cd /home/vchuravy/src/julia/deps/srccache/llvm && git remote set-url origin https://github.com/JuliaLang/llvm-project.git
touch -c /home/vchuravy/src/julia/deps/srccache/llvm/CMakeLists.txt # old target
echo 1 > /home/vchuravy/src/julia/deps/srccache/llvm/source-extracted
# try to update the cache, if that fails, attempt to continue anyways (the ref might already be local)
cd /home/vchuravy/src/julia/deps/srccache/llvm.git && git fetch -q https://github.com/JuliaLang/llvm-project.git julia-14.0.6-2:remotes/origin/julia-14.0.6-2
cd /home/vchuravy/src/julia/deps/srccache/llvm && git fetch -q /home/vchuravy/src/julia/deps/srccache/llvm.git remotes/origin/julia-14.0.6-2:remotes/origin/julia-14.0.6-2
cd /home/vchuravy/src/julia/deps/srccache/llvm && git checkout -q --detach julia-14.0.6-2
\033[33;1m==> warning: SHA1 hash did not match llvm.version file\033[0m
echo 1 > /home/vchuravy/src/julia/deps/srccache/llvm/source-extracted

```

Note the `/home/vchuravy/src/julia/deps/srccache/llvm/source-extracted` marker file.  
`/home/vchuravy/src/julia/deps/srccache/llvm/` now contains a proper checkout that you can work on or modify.

Using `make -C deps configure-llvm` to setup the build.

```julia
vchuravy@odin ~/b/julia-llvmgit> make -C deps configure-llvm
...
-- Build files have been written to: /home/vchuravy/builds/julia-llvmgit/deps/llvm/build_Release
echo 1 > llvm/build_Release/build-configured
make: Leaving directory '/home/vchuravy/builds/julia-llvmgit/deps'

```

Now what happens when I modify a source file.

```julia
vchuravy@odin ~/b/julia-llvmgit> touch /home/vchuravy/src/julia/deps/srccache/llvm/llvm/CMakeLists.txt 
vchuravy@odin ~/b/julia-llvmgit> make -C deps configure-llvm
make: Entering directory '/home/vchuravy/builds/julia-llvmgit/deps'
make: Nothing to be done for 'configure-llvm'.
make: Leaving directory '/home/vchuravy/builds/julia-llvmgit/deps'

```

As we can see the “touch” isn’t picked up. This is due to Julia using “Make markers” so we also need:

```julia
touch /home/vchuravy/src/julia/deps/srccache/llvm/source-extracted 

```

Hope that helps!
