feat: symlink all deps using symlinkJoin
This commit is contained in:
parent
68fbcfb32e
commit
7e18cfab68
3 changed files with 17 additions and 49 deletions
32
README.md
32
README.md
|
|
@ -1,18 +1,6 @@
|
|||
# wasm-sdk
|
||||
|
||||
A SDK for LLVM C and C++ WebAssembly development based on Nix.
|
||||
|
||||
It builds all required dependencies (*clang, clang++, wasm-ld, libcxx, compiler-rt*, and *wasi-libc*)
|
||||
and exposes the following environment variables needed to compile to WebAssembly, for example:
|
||||
|
||||
```
|
||||
WASM_LLVM=/nix/store/akpcpb9ycb98jjbp6dyg1j65vkwqp1lm-wasm-llvm
|
||||
WASM_LIBCXX_LIB=/nix/store/ll4hi2jkhv8399dhbz6q0qgw97c6hyja-wasm-libcxx/lib
|
||||
WASM_LIBCXX_INC=/nix/store/ll4hi2jkhv8399dhbz6q0qgw97c6hyja-wasm-libcxx/include/c++/v1
|
||||
WASM_COMPILER_RT_LIB=/nix/store/59lmk928vly8126zq7mabzc9123hknj2-wasm-compiler-rt/lib/wasi
|
||||
WASI_LIBC_LIB=/nix/store/qislis4ivwv3l721dbhghax6j4kp3ccb-wasi-libc/lib
|
||||
WASI_LIBC_INC=/nix/store/71k5vk20275571n0bsij42qdasbxc82b-wasi-libc-dev/include
|
||||
```
|
||||
A *Nix*-based SDK for C and C++ development targeting WebAssembly.
|
||||
|
||||
## Goals
|
||||
|
||||
|
|
@ -28,16 +16,10 @@ WASI_LIBC_INC=/nix/store/71k5vk20275571n0bsij42qdasbxc82b-wasi-libc-dev/include
|
|||
|
||||
## Usage
|
||||
|
||||
The included derivation produces a single file with exportable environment variables.
|
||||
The package contains all required dependencies in the following build subdirectories:
|
||||
|
||||
Example:
|
||||
|
||||
```sh
|
||||
env $(cat $(nix-build -E 'with import <nixpkgs> {}; callPackage ./default.nix {}')) printenv
|
||||
```
|
||||
|
||||
A *flake* is also included that exposes the needed variables in the following ways (three ways to choose from, for convenience):
|
||||
|
||||
1. as the `paths` (*attrset* type) *passthru* of the *derivation* of the *default package* (to use in other *flakes*).
|
||||
2. as exported environment variables in the *default development shell* (`nix develop`).
|
||||
3. as text in a file (`nix build` produces the file `./result`).
|
||||
* `bin`: compilers (`clang`, `clang++`) and linker (`wasm-ld`)
|
||||
* `include`: *libc* headers
|
||||
* `include/c++/v1`: *libcxx* headers
|
||||
* `lib`: all *libc* and *libcxx* static libraries
|
||||
* `lib/wasi`: compiler-rt builtins static library
|
||||
|
|
|
|||
33
default.nix
33
default.nix
|
|
@ -1,34 +1,21 @@
|
|||
{ pkgs, lib, ... }:
|
||||
{ pkgs, ... }:
|
||||
let
|
||||
wasm-llvm = import ./wasm-llvm.nix { inherit pkgs; };
|
||||
wasm-libcxx = import ./wasm-libcxx.nix { inherit pkgs; };
|
||||
wasi-libc = import ./wasi-libc.nix { inherit pkgs; };
|
||||
wasm-compiler-rt = import ./wasm-compiler-rt.nix { inherit pkgs; };
|
||||
|
||||
paths = {
|
||||
WASM_LLVM = wasm-llvm;
|
||||
WASM_LIBCXX_LIB = "${wasm-libcxx}/lib";
|
||||
WASM_LIBCXX_INC = "${wasm-libcxx}/include/c++/v1";
|
||||
WASM_COMPILER_RT_LIB = "${wasm-compiler-rt}/lib/wasi";
|
||||
WASI_LIBC_LIB = "${wasi-libc}/lib";
|
||||
WASI_LIBC_INC = "${wasi-libc.dev}/include";
|
||||
};
|
||||
|
||||
pathsFileContents = lib.strings.concatLines (
|
||||
lib.attrsets.mapAttrsToList (name: value: name + "=" + value) paths
|
||||
);
|
||||
in
|
||||
pkgs.stdenv.mkDerivation rec {
|
||||
pkgs.symlinkJoin {
|
||||
name = "wasm-sdk";
|
||||
version = "1.0.0";
|
||||
|
||||
paths = [
|
||||
wasm-llvm
|
||||
wasm-libcxx
|
||||
wasi-libc
|
||||
wasi-libc.dev
|
||||
wasm-compiler-rt
|
||||
];
|
||||
|
||||
dontUnpack = true;
|
||||
|
||||
installPhase = ''
|
||||
echo "${pathsFileContents}" > $out
|
||||
'';
|
||||
|
||||
passthru = {
|
||||
inherit paths;
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,5 @@
|
|||
{
|
||||
packages.x86_64-linux.default = package;
|
||||
formatter.x86_64-linux = pkgs.nixfmt-rfc-style;
|
||||
devShells.x86_64-linux.default = pkgs.mkShell package.paths;
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue