Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
{
devShells.default = pkgs.mkShell {
packages = [
inputs'.fenix.packages.stable.defaultToolchain
pkgs.nurl
];

Expand Down
1 change: 1 addition & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ pub struct Opts {
#[derive(Clone, ValueEnum)]
#[clap(rename_all = "camelCase")]
pub enum BuilderFunction {
BuildDunePackage,
BuildGoModule,
BuildNpmPackage,
BuildPythonApplication,
Expand Down
13 changes: 13 additions & 0 deletions src/codegen/dune.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use parse_display::Display;

use crate::codegen::Builder;

#[derive(Clone, Copy, Display)]
#[display("buildDunePackage")]
pub struct BuildDunePackage;

impl Builder for BuildDunePackage {
fn function(&self) -> &'static str {
"buildDunePackage"
}
}
8 changes: 6 additions & 2 deletions src/codegen/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub mod drv;
pub mod dune;
pub mod go;
pub mod npm;
pub mod python;
Expand Down Expand Up @@ -26,8 +27,8 @@ use tracing::warn;
use crate::{
cli::CargoVendor,
codegen::{
drv::MkDerivation, go::BuildGoModule, npm::BuildNpmPackage, python::BuildPythonPackage,
rust::BuildRustPackage,
drv::MkDerivation, dune::BuildDunePackage, go::BuildGoModule, npm::BuildNpmPackage,
python::BuildPythonPackage, rust::BuildRustPackage,
},
frontend::FrontendDispatch,
inputs::{AllInputs, write_all_lambda_inputs, write_inputs, write_lambda_input},
Expand All @@ -43,6 +44,7 @@ use crate::{
#[derive(Clone, Copy, Display)]
#[display("{0}")]
pub enum BuilderDispatch {
BuildDunePackage(BuildDunePackage),
BuildGoModule(BuildGoModule),
BuildNpmPackage(BuildNpmPackage),
BuildPythonPackage(BuildPythonPackage),
Expand Down Expand Up @@ -77,6 +79,7 @@ pub struct Codegen<'a> {
pub struct SourceLayout {
pub has_cargo: bool,
pub has_cargo_lock: bool,
pub has_dune: bool,
pub has_cmake: bool,
pub has_go: bool,
pub has_meson: bool,
Expand Down Expand Up @@ -473,6 +476,7 @@ impl SourceLayout {
has_cargo_lock: src_dir.join("Cargo.lock").is_file(),
has_cmake: src_dir.join("CMakeLists.txt").is_file(),
has_go: src_dir.join("go.mod").is_file(),
has_dune: src_dir.join("dune-project").is_file(),
has_meson: src_dir.join("meson.build").is_file(),
has_npm: src_dir.join("package.json").is_file(),
has_npm_lock: src_dir.join("package-lock.json").is_file()
Expand Down
16 changes: 13 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,15 @@ use zip::ZipArchive;

use crate::{
cfg::load_config,
cli::{BuilderFunction, CargoVendor, Opts},
cli::{
BuilderFunction::{self},
CargoVendor, Opts,
},
cmd::{NIX, NURL},
codegen::{
BuilderDispatch, Codegen, SourceLayout, drv::MkDerivation, go::BuildGoModule,
npm::BuildNpmPackage, python::BuildPythonPackage, rust::BuildRustPackage,
BuilderDispatch, Codegen, SourceLayout, drv::MkDerivation, dune::BuildDunePackage,
go::BuildGoModule, npm::BuildNpmPackage, python::BuildPythonPackage,
rust::BuildRustPackage,
},
fetcher::{Fetcher, FetcherDispatch, PackageInfo, PypiFormat, Revisions, Version},
frontend::{Frontend, headless, readline},
Expand Down Expand Up @@ -384,6 +388,7 @@ async fn run() -> Result<()> {

let builder = match (opts.builder, opts.cargo_vendor) {
(Some(builder), rust @ Some(vendor)) if layout.has_cargo => match builder {
BuilderFunction::BuildDunePackage => BuildDunePackage.into(),
BuilderFunction::BuildGoModule => BuildGoModule.into(),
BuilderFunction::BuildNpmPackage => BuildNpmPackage.into(),
BuilderFunction::BuildPythonApplication => BuildPythonPackage::new(true, rust).into(),
Expand All @@ -395,6 +400,7 @@ async fn run() -> Result<()> {
(Some(builder), _) => {
let rust = layout.has_cargo.then_some(CargoVendor::FetchCargoVendor);
match builder {
BuilderFunction::BuildDunePackage => BuildDunePackage.into(),
BuilderFunction::BuildGoModule => BuildGoModule.into(),
BuilderFunction::BuildNpmPackage => BuildNpmPackage.into(),
BuilderFunction::BuildPythonApplication => {
Expand Down Expand Up @@ -438,6 +444,10 @@ async fn run() -> Result<()> {
}
}

if layout.has_dune {
builders.push(BuildDunePackage.into());
}

if layout.has_python {
for application in [true, false] {
builders.push(BuildPythonPackage::new(application, None).into());
Expand Down
30 changes: 30 additions & 0 deletions tests/cmd/dune.out/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
lib,
buildDunePackage,
fetchFromGitHub,
nix-update-script,
}:

buildDunePackage (finalAttrs: {
pname = "ocaml-lsp";
version = "1.27.0";
__structuredAttrs = true;

src = fetchFromGitHub {
owner = "ocaml";
repo = "ocaml-lsp";
tag = finalAttrs.version;
hash = "sha256-XrNYqNeaJAvkSYU0vha0apbN9uAYiGIuiJJMJMAN5ug=";
};

passthru.updateScript = nix-update-script { };

meta = {
description = "[..]";
homepage = "https://github.com/ocaml/ocaml-lsp";
changelog = "https://github.com/ocaml/ocaml-lsp/blob/${finalAttrs.src.rev}/CHANGES.md";
license = lib.licenses.isc;
maintainers = with lib.maintainers; [ alice ];
mainProgram = "ocaml-lsp";
};
})
5 changes: 5 additions & 0 deletions tests/cmd/dune.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
args = [
"--headless",
"--url=https://github.com/ocaml/ocaml-lsp",
"--rev=1.27.0",
]