From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id A01557F7AF for ; Mon, 5 Oct 2015 18:03:35 +0200 (CEST) IronPort-PHdr: 9a23:xYqOuBS/50hBRDYdkLzKJpkbTtpsv+yvbD5Q0YIujvd0So/mwa64ZxON2/xhgRfzUJnB7Loc0qyN4/ymBzxLsMzJmUtBWaIPfidNsd8RkQ0kDZzNImzAB9muURYHGt9fXkRu5XCxPBsdMs//Y1rPvi/6tmZKSV3BPAZ4bt74BpTVx5zukbvip9uNM04Z3nKUWvBbElaflU3prM4YgI9veO4a6yDihT92QdlQ3n5iPlmJnhzxtY+a9Z9n9DlM6bp6r5YTGfayQ6NtRrVdCHEiMnspzMztrxjKCwWVtVUGVWBDuRpSAhPZ7Rj8FrPwtCf7uaIp3CicMcz5Zb8xUDWmqaxsTUm72288Kzcl/TSP2YRLh6VBrUf5qg== Authentication-Results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=lindig@gmail.com; spf=Pass smtp.mailfrom=lindig@gmail.com; spf=None smtp.helo=postmaster@mail-wi0-f179.google.com Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of lindig@gmail.com) identity=pra; client-ip=209.85.212.179; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="lindig@gmail.com"; x-sender="lindig@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of lindig@gmail.com designates 209.85.212.179 as permitted sender) identity=mailfrom; client-ip=209.85.212.179; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="lindig@gmail.com"; x-sender="lindig@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-wi0-f179.google.com) identity=helo; client-ip=209.85.212.179; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="lindig@gmail.com"; x-sender="postmaster@mail-wi0-f179.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0DOAADLnhJWlLPUVdFeFoNlbrIQjWsjhS2BfTsRAQEBAQEBAQEQAQEBAQcLCwkfMIIdgiARHQEbHgMSEA8CJgIlEQEFAVeHdgEDEgQBCJkLggiBMD4xi0mBbIJ5iUAKGScNVoQ2AQoBAQEBAQEVAQUOgRSHYYgZglIvgRQFhxmLMIMzhReIAIIdhmEMBJEJNYEXN4JTgV1vAYg+AQEB X-IPAS-Result: A0DOAADLnhJWlLPUVdFeFoNlbrIQjWsjhS2BfTsRAQEBAQEBAQEQAQEBAQcLCwkfMIIdgiARHQEbHgMSEA8CJgIlEQEFAVeHdgEDEgQBCJkLggiBMD4xi0mBbIJ5iUAKGScNVoQ2AQoBAQEBAQEVAQUOgRSHYYgZglIvgRQFhxmLMIMzhReIAIIdhmEMBJEJNYEXN4JTgV1vAYg+AQEB X-IronPort-AV: E=Sophos;i="5.17,639,1437429600"; d="scan'208";a="149693526" Received: from mail-wi0-f179.google.com ([209.85.212.179]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/AES128-GCM-SHA256; 05 Oct 2015 18:03:34 +0200 Received: by wicfx3 with SMTP id fx3so127334409wic.1 for ; Mon, 05 Oct 2015 09:03:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:content-type:content-transfer-encoding:subject:message-id:date :to:mime-version; bh=fN3CUkwAOLQcE+H/1j/M4K2DRMoBmyO1tKzsH8db+zg=; b=wKt6Ul8dRCCZ7j9vtgm0f6C8tGFNPF9Q559iIPva9gQDSwhnmizEu+VlSmYYCj1fwo n6iqckJAoAYtPBlISxKu3hjKA1NczoT8obmVJcxl629agHFuVm0sX53or4Mf7DWkqRkt fdRQ2piOFmkMTMwOFp4syum4OlrC7WAQP6IF0z4zkM08p6Z0Nn6hWlQZT/I1rFhybRvB WYkp3lB3bpJteJWCfSB1afL8TbCr+dAES27AQ8O1eT4qRtQxyaqG/jl8srXdnV+8vDoZ EVovEDf2/wM8PBN1FkxNHDDNVUHtbgicrEXN4BBZJIRMCVW3GdHeI3h7MfnI7cmE1h0Y 6V+Q== X-Received: by 10.194.21.163 with SMTP id w3mr31027023wje.70.1444061014685; Mon, 05 Oct 2015 09:03:34 -0700 (PDT) Received: from [192.168.178.42] (ipservice-092-212-033-022.092.212.pools.vodafone-ip.de. [92.212.33.22]) by smtp.gmail.com with ESMTPSA id az6sm15339612wib.12.2015.10.05.09.03.32 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 05 Oct 2015 09:03:33 -0700 (PDT) From: Christian Lindig Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Message-Id: <6BA70943-6E5D-4123-92AE-0FCC87628F38@gmail.com> Date: Mon, 5 Oct 2015 18:03:32 +0200 To: caml-list@inria.fr Mime-Version: 1.0 (Mac OS X Mail 8.2 \(2104\)) X-Mailer: Apple Mail (2.2104) X-Validation-by: lindig@gmail.com Subject: [Caml-list] Using OCamlbuild with C stubs What is the recommended way to use OCamlbuild when implementing a few primi= tives in C? I=E2=80=99ve seen several blog posts about this and I feel there are some s= truggles.=20 * https://ocaml.org/learn/tutorials/ocamlbuild/Ocamlbuild_example_with_C_st= ubs.html This is quite involved and requires experience with customizing OCamlbuild = using the myocamlbuild.ml mechanism. * http://l-lang.blogspot.de/2012/08/incorporating-c-code-in-ocaml-project.h= tml This approach implements a minimal new parameterised tag to express that th= e C object code needs to be linked into the final binary. I had trouble get= ting it to work when the project spans several directories. But if it works= , maybe it should be a built-in tag? * http://mancoosi.org/~abate/ocamlbuild-and-c-stubs This strikes a middle ground. Maybe the projects are so different that there is no one way. I believe one= core problem is to express that an object file or local C library needs to= be linked into the binary.=20 During experiments I came up with an approach that doesn=E2=80=99t require = myocamlbuild.ml but seems like a hack:=20 $ ocamlbuild -I src -I lib -lflag lib/libpath.a libpath.a main.byte Building libpath.a is triggered by naming it as a target on the command lin= e; likewise, linking it to the binary main.byte is expressed using the link= er flag =E2=80=9C-lflag=E2=80=9D. This works around the problem that a buil= t-in mechanism seems to be missing to express this dependency using tags. Project layout: ./_tags ./lib/libpath.clib # lists pathutil.o ./lib/pathutil.c # new primitive in C ./lib/pathutil.mli # interface ./src/main.ml _tags file: <**/main.byte>: custom You can find it as examples/06-simple-c in my clone of the ocamlbuild manua= l that Gabriel Scherer is working on: https://github.com/lindig/manual-ocam= lbuild. I understand that dependencies among C files need to be handled as well but= would solve this problem outside of Ocamlbuild. =E2=80=94 Christian