diff --git a/.gitignore b/.gitignore index 65d8d32..df15b77 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,13 @@ syntax: glob +# Misc +/.direnv +/.envrc + +# Bazel +bazel-* +MODULE.bazel.lock + # Temporary, cache, swap files \#\#* *.swp diff --git a/BUILD.bazel b/BUILD.bazel index a6cd021..a66fae7 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -6,11 +6,3 @@ cc_library( strip_include_prefix = "include", visibility = ["//visibility:public"], ) - -load("@rules_fuzzing//fuzzing:cc_defs.bzl", "cc_fuzz_test") - -cc_fuzz_test( - name = "cxxopts_fuzz_test", - srcs = ["test/fuzz.cpp"], - deps = [":cxxopts"], -) \ No newline at end of file diff --git a/MODULE.bazel b/MODULE.bazel new file mode 100644 index 0000000..482681e --- /dev/null +++ b/MODULE.bazel @@ -0,0 +1,7 @@ +module( + name = "cxxopts", + version = "3.2.0", + compatibility_level = 0, +) + +bazel_dep(name = "rules_cc", version = "0.1.1") diff --git a/WORKSPACE b/WORKSPACE deleted file mode 100644 index 6a0fa27..0000000 --- a/WORKSPACE +++ /dev/null @@ -1,16 +0,0 @@ -load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") - -http_archive( - name = "rules_fuzzing", - sha256 = "d9002dd3cd6437017f08593124fdd1b13b3473c7b929ceb0e60d317cb9346118", - strip_prefix = "rules_fuzzing-0.3.2", - urls = ["https://github.com/bazelbuild/rules_fuzzing/archive/v0.3.2.zip"], -) - -load("@rules_fuzzing//fuzzing:repositories.bzl", "rules_fuzzing_dependencies") - -rules_fuzzing_dependencies() - -load("@rules_fuzzing//fuzzing:init.bzl", "rules_fuzzing_init") - -rules_fuzzing_init() diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..376925f --- /dev/null +++ b/flake.lock @@ -0,0 +1,61 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1743583204, + "narHash": "sha256-F7n4+KOIfWrwoQjXrL2wD9RhFYLs2/GGe/MQY1sSdlE=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "2c8d3f48d33929642c1c12cd243df4cc7d2ce434", + "type": "github" + }, + "original": { + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "2c8d3f48d33929642c1c12cd243df4cc7d2ce434", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..879c5ea --- /dev/null +++ b/flake.nix @@ -0,0 +1,164 @@ +{ + description = "fpga-assembler"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/2c8d3f48d33929642c1c12cd243df4cc7d2ce434"; + 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; + } + ); + } + ); + } + ); +}