Assistance packaging semgrep (OCaml + Dune)

Hi all,

I’m attempting to package semgrep, but I’ve found myself in deep water with OCaml/Dune. To summarize where I’m at, semgrep uses Python as the main interface but relies on semgrep_core underneath the hood which is an OCaml project. The source for the core is located in the same repository.

This was my initial attempt at writing a package for core:

{ lib
, ocamlPackages
, fetchFromGitHub
}:

with ocamlPackages;
buildDunePackage rec {
  pname = "semgrep_core";
  version = "0.92.1";

  src = fetchFromGitHub {
    owner = "returntocorp";
    repo = "semgrep";
    rev = "refs/tags/v${version}";
    sha256 = "sha256-rZhp2eeNmBjhH96MQC1z6ytPe0MNnkeVOp9cdRr6Y4w=";
  };

  nativeBuildInputs = [ atdge ];
}

This fails with an error:

> File "semgrep-core/src/core/dune", line 1, characters 0-0:
> Error: File unavailable: semgrep-core/src/core/Semgrep_output_v0.atd
> File "semgrep-core/src/core/dune", line 20, characters 5-18:
> 20 |      ppx_profiling
>             ^^^^^^^^^^^^^
> Error: Library "ppx_profiling" not found.

At this point, I’m pretty lost because I’ve never dealt with OCaml or Dune, so I’m not sure if I need to bring in this dependency or if I’m just doing something wrong (searching nixpkgs didn’t bring up anything matching the dependency).

Any help is appreciated!

1 Like

So I ended up finding where ppx_profiling exists, it’s in returntocorp/pfff. However, it’s on the develop branch and not in master, which is a bit weird. I don’t see anywhere where this branch is referenced or how dune would know to pull from there.

I noticed that someone’s also recently opened a PR on semgrep @ semgrep: init at 0.92.0 by KAction · Pull Request #172808 · NixOS/nixpkgs · GitHub

Don’t let this dissuade you–I’m just cross-linking these in case more hands/eyes make the problem shallower. You’re taking the right approach in building the semgrep core from source; you can see that skipping this step is a sticking point for the reviewers in that PR.

1 Like

Thanks for mentioning this, I’ll move this conversation to the PR.

Also for pfff, see ocamlPackages.pfff: init at 2021-12-14 by jtojnar · Pull Request #151722 · NixOS/nixpkgs · GitHub

Hosted by Flying Circus.