Skip to content

Commit 4311944

Browse files
committed
Build with nix
1 parent 8b5ae80 commit 4311944

File tree

3 files changed

+133
-0
lines changed

3 files changed

+133
-0
lines changed

.github/workflows/nix.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
name: "Nix checks"
3+
on:
4+
pull_request:
5+
branches: [main]
6+
push:
7+
branches: [main]
8+
jobs:
9+
nixflake:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
with:
14+
submodules: recursive
15+
- uses: cachix/install-nix-action@v29
16+
with:
17+
github_access_token: ${{ secrets.GITHUB_TOKEN }}
18+
- run: nix build
19+
- run: nix flake check
20+
nixfmt:
21+
runs-on: ubuntu-latest
22+
steps:
23+
- uses: actions/checkout@v4
24+
with:
25+
submodules: recursive
26+
- uses: nixbuild/nix-quick-install-action@v29
27+
- name: nix fmt
28+
run: nix fmt $(find . -name \*nix -type f -not -path "./.git/*")
29+
- name: Changed files
30+
id: dirty
31+
run: |
32+
echo "Checking nix files with: nix fmt ..."
33+
git diff --exit-code
34+
continue-on-error: true
35+
- name: Failure case
36+
if: steps.dirty.outcome != 'success'
37+
run: |
38+
echo "Please fix formatting with nix fmt (file)"
39+
exit 1
40+
- name: Success
41+
run: echo "All nix files passed format check"

aws-lc-sys/builder/cc_builder.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,8 +383,11 @@ impl CcBuilder {
383383
let mut new_cflags = original_cflags.clone();
384384
// The `_FORTIFY_SOURCE` macro often requires optimizations to also be enabled, so unset it.
385385
new_cflags.push_str(" -O0 -Wp,-U_FORTIFY_SOURCE");
386+
/*
387+
Reproduce the failure, then we'll find the best place to put this.
386388
// Certain MacOS system headers are guarded by _POSIX_C_SOURCE and _DARWIN_C_SOURCE
387389
new_cflags.push_str(" -D_DARWIN_C_SOURCE");
390+
*/
388391
set_env_for_target("CFLAGS", &new_cflags);
389392
// cc-rs currently prioritizes flags provided by CFLAGS over the flags provided by the build script.
390393
// The environment variables used by the compiler are set when `get_compiler` is called.

flake.nix

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
{
2+
description = "aws-lc-rs is a cryptographic library using AWS-LC for its cryptographic operations";
3+
4+
inputs = {
5+
nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.11";
6+
flake-utils.url = "github:numtide/flake-utils";
7+
};
8+
9+
outputs = { self, nixpkgs, flake-utils }:
10+
flake-utils.lib.eachDefaultSystem (system:
11+
let
12+
pkgs = nixpkgs.legacyPackages.${system};
13+
14+
# Common build inputs needed for aws-lc-sys
15+
awsLcBuildInputs = with pkgs; [
16+
cmake
17+
ninja
18+
perl
19+
go
20+
clang
21+
];
22+
23+
aws-lc-rs = pkgs.rustPlatform.buildRustPackage {
24+
pname = "aws-lc-rs";
25+
version = "1.0.0";
26+
27+
src = ./.;
28+
29+
cargoLock = {
30+
lockFile = ./Cargo.lock;
31+
};
32+
33+
nativeBuildInputs = awsLcBuildInputs;
34+
35+
# Environment variables needed for building aws-lc
36+
preBuild = ''
37+
export HOME=$PWD
38+
'';
39+
40+
# Run tests
41+
checkPhase = ''
42+
cargo test --workspace --all-features
43+
'';
44+
45+
doCheck = true;
46+
47+
meta = with pkgs.lib; {
48+
description = "aws-lc-rs is a cryptographic library using AWS-LC";
49+
homepage = "https://github.com/aws/aws-lc-rs";
50+
license = with licenses; [ asl20 isc ];
51+
};
52+
};
53+
54+
devShell = pkgs.mkShell {
55+
name = "aws-lc-rs-dev";
56+
57+
buildInputs = with pkgs; [
58+
# Rust toolchain
59+
rustc
60+
cargo
61+
rustfmt
62+
clippy
63+
rust-analyzer
64+
65+
# AWS-LC build dependencies
66+
] ++ awsLcBuildInputs;
67+
68+
shellHook = ''
69+
echo "aws-lc-rs development environment"
70+
echo "Rust version: $(rustc --version)"
71+
'';
72+
};
73+
74+
in rec {
75+
packages = {
76+
aws-lc-rs = aws-lc-rs;
77+
default = aws-lc-rs;
78+
};
79+
80+
formatter = pkgs.nixfmt-classic;
81+
82+
devShells.default = devShell;
83+
84+
# Checks that run in CI
85+
checks = {
86+
inherit aws-lc-rs;
87+
};
88+
});
89+
}

0 commit comments

Comments
 (0)