Skip to content

repo: removed shell.nix and moved to nix flakes #28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 4, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .bazelignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# While using flakes, bazel might pickup the sources used
# as flake input stored in direnv and lead to a broken build.
.direnv
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ It has been tested with the Artix-7 [counter example][counter-example], where it

## Usage

First, install [Bazel][bazel] and ensure you have a basic C/C++ toolchain set up. Then run:
First, install [Bazel][bazel] and ensure you have a basic C/C++ toolchain set up.

> [!NOTE]
> If you are using Nix or NixOS, ensure you have [flakes enabled][enable-flakes] and enter the development shell via `nix develop`.

Then run:

```
bazel run -c opt //fpga:fpga-as -- --prjxray_db_path=/some/path/prjxray-db/artix7 --part=xc7a35tcsg324-1 < /some/path.fasm > output.bit
Expand Down Expand Up @@ -66,3 +71,4 @@ Using this metadata, you can search the segbits database for the specific featur
[bazel]: https://bazel.build/
[counter-example]: https://github.com/chipsalliance/f4pga-examples/blob/13f11197b33dae1cde3bf146f317d63f0134eacf/xc7/counter_test/counter.v
[open-fpga-loader]: https://github.com/trabucayre/openFPGALoader
[enable-flakes]: https://nixos.wiki/wiki/Flakes#Enable_flakes_permanently_in_NixOS
61 changes: 61 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

147 changes: 147 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
{
description = "fpga-assembler";

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd probably fix that to a commit or 24.11 so that we don't create a new flake derivation every day nixos-unstable changes.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I studied a bit more flakes, as long as the flake.lock doesn't get updated, the channel is pinned.

"rev": "2c8d3f48d33929642c1c12cd243df4cc7d2ce434",

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to be explicit.
The lock file is a non-human readable format to be explicit.
So we should put the version in the flake.nix to be human readably explicit.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Upsie! I'll make a commit that adds a specific revision then!

flake-utils.url = "github:numtide/flake-utils";
};

outputs = { self, nixpkgs, flake-utils } @inputs:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
};
common = with pkgs; {
bazel = bazel_7;
jdk = jdk;
};
in {
devShells.default =
let
# There is too much volatility between even micro-versions of
# newer clang-format. Use slightly older version for now.
clang_for_formatting = pkgs.llvmPackages_17.clang-tools;

# clang tidy: use latest.
clang_for_tidy = pkgs.llvmPackages_18.clang-tools;
in with pkgs; pkgs.mkShell{
packages = with pkgs; [
git
common.bazel
common.jdk
bash
gdb

# For clang-tidy and clang-format.
clang_for_formatting
clang_for_tidy

# For buildifier, buildozer.
bazel-buildtools
bant

# Profiling and sanitizers.
linuxPackages_latest.perf
pprof
perf_data_converter
valgrind

# FPGA utils.
openfpgaloader
];

CLANG_TIDY="${clang_for_tidy}/bin/clang-tidy";
CLANG_FORMAT="${clang_for_formatting}/bin/clang-format";

shellHook = ''
exec bash
'';
};

# Package fpga-assembler.
packages.default = (pkgs.callPackage (
{
buildBazelPackage,
stdenv,
fetchFromGitHub,
lib,
nix-gitignore,
}:
let
system = stdenv.hostPlatform.system;
registry = fetchFromGitHub {
owner = "bazelbuild";
repo = "bazel-central-registry";
rev = "63f3af762b2fdd7acaa7987856cd3ac314eaea09";
hash = "sha256-ugNzoP0gdrhl9vH1TRdwoevuTsSqjitXnAoMSSTlCgI=";
};
in
buildBazelPackage {
pname = "fpga-as";

version = "0.0.1";

src = nix-gitignore.gitignoreSourcePure [] ./.;

bazelFlags = [
"--registry"
"file://${registry}"
];

postPatch = ''
patchShebangs scripts/create-workspace-status.sh
'';

fetchAttrs = {
hash =
{
aarch64-linux = "sha256-E4VHjDa0qkHmKUNpTBfJi7dhMLcd1z5he+p31/XvUl8=";
x86_64-linux = "sha256-hVBJB0Hsd9sXuEoNcjhTkbPl89vlZT1w39JppCD+n8Y=";
}
.${system} or (throw "No hash for system: ${system}");
};

removeRulesCC = false;
removeLocalConfigCc = false;
removeLocalConfigSh = false;

nativeBuildInputs = [
common.jdk
pkgs.git
pkgs.bash
# Convenient tool to enter into the sandbox and start debugging.
pkgs.breakpointHook
];

bazel = common.bazel;

bazelBuildFlags = [ "-c opt" ];
bazelTestTargets = [ "//..." ];
bazelTargets = [ "//fpga:fpga-as" ];

buildAttrs = {
installPhase = ''
install -D --strip bazel-bin/fpga/fpga-as "$out/bin/fpga-as"
'';
};

meta = {
description = "Tool to convert FASM to FPGA bitstream.";
homepage = "https://github.com/lromor/fpga-assembler";
license = lib.licenses.asl20;
platforms = lib.platforms.linux;
};
}
) {}).overrideAttrs (final: prev: {
# Fixup the deps so they always contain correrct
# shebangs paths pointing to the store.
deps = prev.deps.overrideAttrs (final: prev: {
installPhase = ''
patchShebangs $bazelOut/external
'' + prev.installPhase;
});
});
}
);
}
4 changes: 3 additions & 1 deletion fpga/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ package(
license(
name = "license",
package_name = "fpga",
license_kind = "@rules_license//licenses/spdx:Apache-2.0",
license_kinds = [
"@rules_license//licenses/spdx:Apache-2.0",
],
)

cc_library(
Expand Down
4 changes: 3 additions & 1 deletion fpga/xilinx/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ package(
license(
name = "license",
package_name = "xilinx",
license_kind = "@rules_license//licenses/spdx:ISC",
license_kinds = [
"@rules_license//licenses/spdx:ISC",
],
)

cc_library(
Expand Down
41 changes: 0 additions & 41 deletions shell.nix

This file was deleted.