Sunday, January 2, 2022

Using WSL for Solana development

Why? Solana tooling for Windows does not allow for BPF builds.

How?

  • Run WSL on Windows
  • If you are behind a company firewall:
    • make sure you have a .pem file of your root certificate. Talk your sysadmin for that. If you have a .cer file - make sure you convert it to .pem
    • Make sure you have an environment variable SSL_CERT_FILE to point at your .pem certificate (use "export SSL_CERT_FILE=" for that from inside your wsl command shell) or event better - add it to your ~/bashrc file
  • sudo apt install build-essential
  • curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
  • sudo apt install pkg-config
  • sudo apt install libudev-dev
  • sudo apt install llvm-dev
  • sudo apt install clang

Build and run solana-bpf-program-template on Windows

It turns out that compiling a very basic solana-bpf-program-template on Windows is not a very easy task to do.

First, it panicked with the following error:

error: failed to run custom build command for `openssl-sys ...

In order to solve this an install of the OpenSSL package is needed. Compiling it may have more tricks in it so I decided to install a pre-built package from here. I went to the "Win64 OpenSSL v1.1.1m" option. either .EXE or .MSI. It's important to select the OpenSSL 1.1.1 and not another version. When installing make sure the environment variable of OPENSSL_DIR is set. If not - please set it manually to the root directory of the installation.

Once this issue was resolved the "cargo build" phase progressed further to halt this time with the following error:

   Compiling soketto v0.7.1
error: failed to run custom build command for `librocksdb-sys v6.20.3`

Caused by:
  process didn't exit successfully: `D:\Projects\solana\solana-bpf-program-template\target\debug\build\librocksdb-sys-67f01990a368d2b7\build-script-build` (exit code: 101)
  --- stderr
  thread 'main' panicked at 'Unable to find libclang: "couldn't find any valid shared libraries matching: ['clang.dll', 'libclang.dll'], set the `LIBCLANG_PATH` environment variable to a path where one of these files can be found (invalid: [])"'

In order to resolve this I had to google the LIBCLANG_PATH to discover that I need the LLVM compiler. It can be downloaded from here  Please make sure that you select registering the environment variables as a part of the installation.