Skip to content

Commit

Permalink
build: Static build with glibc
Browse files Browse the repository at this point in the history
This is a first iteration, glibc is not a great idea for most statically
linked applciations. It should be fine for now, but we should rework
this using musl or other approaches.
  • Loading branch information
javierhonduco committed Mar 27, 2024
1 parent 074555f commit 49da228
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 8 deletions.
8 changes: 8 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
BasedOnStyle: Google

AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
ColumnLimit: 120
IndentWidth: 4
SortIncludes: false
36 changes: 36 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: release

on:
pull_request:
push:

# on:
# push:
# branches:
# - main

jobs:
release:
runs-on: ubuntu-22.04
permissions:
id-token: write
contents: read

steps:
- uses: actions/checkout@main
- uses: DeterminateSystems/nix-installer-action@main
- uses: DeterminateSystems/magic-nix-cache-action@main

- name: Set up nix dev env
run: nix develop --command echo 0

- name: Build statically linked lightswitch with glibc
run: |
nix develop
RUSTFLAGS="-C target-feature=+crt-static" cargo build --release --target x86_64-unknown-linux-gnu
- name: Upload binary
uses: actions/upload-artifact@main
with:
name: lightswitchs
path: target/x86_64-unknown-linux-gnu/release/lightswitch
4 changes: 0 additions & 4 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,8 @@ const PROFILER_BPF_SOURCE: &str = "./src/bpf/profiler.bpf.c";
const PROFILER_SKELETON: &str = "./src/bpf/profiler_skel.rs";

fn main() {
// This is necessary but not sure why, this should be passed elsewhere
println!("cargo:rustc-link-lib=zstd");

// Inform cargo of when to re build
println!("cargo:rerun-if-changed={PROFILER_BPF_HEADER}");
println!("cargo:rerun-if-changed={PROFILER_BPF_HEADER}");
println!("cargo:rerun-if-changed={PROFILER_BPF_SOURCE}");

let bindings = bindgen::Builder::default()
Expand Down
9 changes: 5 additions & 4 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
pkgs = import nixpkgs {
inherit system overlays;
};
zstd-static = (pkgs.zstd.override { static = true; });
elfutils-without-zstd = pkgs.elfutils.overrideAttrs (attrs: {
configureFlags = attrs.configureFlags ++ [ "--without-zstd" ];
});
in
with pkgs;
{
Expand All @@ -42,18 +44,17 @@
# Native deps
glibc
glibc.static
elfutils
elfutils-without-zstd
zlib.static
zlib.dev
openssl
zstd-static
# Other tools
cargo-edit
# ocamlPackages.magic-trace
];

LIBCLANG_PATH = lib.makeLibraryPath [ llvmPackages_16.libclang ];
LD_LIBRARY_PATH = lib.makeLibraryPath [ zstd-static zlib.static elfutils ];
LD_LIBRARY_PATH = lib.makeLibraryPath [ zlib.static elfutils-without-zstd ];
};
}
);
Expand Down

0 comments on commit 49da228

Please sign in to comment.