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 examples/libpcap/generate-and-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export PROJECT_ROOT
echo "# Building libpcap"
echo "# "

rm -rfv libpcap*
wget https://www.tcpdump.org/release/libpcap-1.10.5.tar.xz
tar -xf libpcap-1.10.5.tar.xz
mv libpcap-1.10.5 libpcap
Expand Down
15 changes: 10 additions & 5 deletions examples/libpcap/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,15 @@ libclang_flags=(
# the declarations into an `hs-bindgen`-internal abstract syntax tree. These
# flags affect the parsing/reifying step.
parse_flags=(
# TODO: We panic without `--parse-all`, see
# https://github.com/well-typed/hs-bindgen/issues/1155.
--parse-all
# The external binding specifications we provide for the C standard library
# do not cover all definitions. We instruct `hs-bindgen` to parse additional
# headers.
--parse-by-header-path "struct_timeval.h"
--parse-by-header-path "socket.h"
# By default `hs-bindgen` parses all headers in the main header directory,
# but we adjust the parse predicate above, and so need to provide this
# option.
--parse-from-main-header-dirs
)

# We only generate bindings for a sub-set of all parsed/reified declarations.
Expand Down Expand Up @@ -56,9 +62,8 @@ select_flags=(
# For example, activate Info-level log messages to see which declarations are
# selected/not selected, or which C macros we succeed or fail to parse.
debug_flags=(
# # Run `hs-bindgen` with log level "Info".
# # Run `hs-bindgen` with log level "Info" or "Debug".
# -v3
# # Run `hs-bindgen` with log level "Debug".
# -v4
)

Expand Down
3 changes: 1 addition & 2 deletions hs-bindgen/examples/golden/declarations/select_scoping.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// select!
#include "select_scoping_header.h"


// This declaration is parsed _and_ selected.
typedef int ParsedAndSelected1;

Expand All @@ -12,4 +11,4 @@ typedef ParsedAndNotSelected ParsedAndSelected2;

// This declaration is parsed _and_ selected. The dependency is _not_ parsed nor
// selected (custom parse predicate).
typedef struct PossiblyNotParsedDefinitelyNotSelected ParsedAndSelected3;
typedef struct ParseNotAttemptedNotSelected ParsedAndSelected3;
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ typedef int ParsedAndNotSelected;

// This declaration is _not_ parsed by the test, which uses a custom parse
// predicate.
struct PossiblyNotParsedDefinitelyNotSelected {
struct ParseNotAttemptedNotSelected {
int x;
};
3 changes: 3 additions & 0 deletions hs-bindgen/examples/golden/edge-cases/duplicate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include "duplicate_macro.h"

void function(duplicate x);
2 changes: 2 additions & 0 deletions hs-bindgen/examples/golden/edge-cases/duplicate_macro.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
typedef int duplicate;
#define duplicate duplicate
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import Prelude (Bounded, Enum, Eq, Integral, Num, Ord, Read, Real, Show)

{-| __C declaration:__ @ParsedAndSelected1@

__defined at:__ @declarations\/select_scoping.h:7:13@
__defined at:__ @declarations\/select_scoping.h:6:13@

__exported by:__ @declarations\/select_scoping.h@
-}
Expand Down
4 changes: 2 additions & 2 deletions hs-bindgen/fixtures/declarations/select_scoping/th.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
-- addDependentFile examples/golden/declarations/select_scoping.h
{-| __C declaration:__ @ParsedAndSelected1@

__defined at:__ @declarations\/select_scoping.h:7:13@
__defined at:__ @declarations\/select_scoping.h:6:13@

__exported by:__ @declarations\/select_scoping.h@
-}
newtype ParsedAndSelected1
= ParsedAndSelected1 {un_ParsedAndSelected1 :: CInt}
{- ^ __C declaration:__ @ParsedAndSelected1@

__defined at:__ @declarations\/select_scoping.h:7:13@
__defined at:__ @declarations\/select_scoping.h:6:13@

__exported by:__ @declarations\/select_scoping.h@
-}
Expand Down
1 change: 1 addition & 0 deletions hs-bindgen/fixtures/edge-cases/duplicate/Example.pp.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module Example () where
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module Example.FunPtr () where
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module Example.Global () where
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module Example.Safe () where
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module Example.Unsafe () where
5 changes: 5 additions & 0 deletions hs-bindgen/fixtures/edge-cases/duplicate/bindingspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
version:
hs_bindgen: 0.1.0
binding_specification: '1.0'
target: x86_64-pc-linux-musl
hsmodule: Example
2 changes: 2 additions & 0 deletions hs-bindgen/fixtures/edge-cases/duplicate/th.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- addDependentFile examples/golden/edge-cases/duplicate_macro.h
-- addDependentFile examples/golden/edge-cases/duplicate.h
1 change: 1 addition & 0 deletions hs-bindgen/hs-bindgen.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ library internal
HsBindgen.Frontend.Naming
HsBindgen.Frontend.Pass
HsBindgen.Frontend.Pass.ConstructTranslationUnit
HsBindgen.Frontend.Pass.ConstructTranslationUnit.Conflict
HsBindgen.Frontend.Pass.ConstructTranslationUnit.IsPass
HsBindgen.Frontend.Pass.HandleMacros
HsBindgen.Frontend.Pass.HandleMacros.Error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import HsBindgen.Backend.SHs.Translation qualified as SHs
import HsBindgen.Backend.UniqueId
import HsBindgen.BindingSpec qualified as BindingSpec
import HsBindgen.Errors
import HsBindgen.Frontend.Analysis.DeclIndex
import HsBindgen.Frontend.Analysis.DeclIndex (DeclIndex)
import HsBindgen.Frontend.Analysis.DeclIndex qualified as DeclIndex
import HsBindgen.Frontend.AST.External qualified as C
import HsBindgen.Frontend.Naming qualified as C
Expand Down
2 changes: 1 addition & 1 deletion hs-bindgen/src-internal/HsBindgen/Backend/UniqueId.hs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ data UniqueIdMsg =
instance PrettyForTrace UniqueIdMsg where
prettyForTrace = \case
UniqueIdEmpty -> PP.vcat [
"empty unique identifier ('UniqueId'):"
"empty unique identifier ('UniqueId', '--unique-id'):"
, " C uses a global namespace."
, " We encourage using a unique identifier to avoid duplicate symbol names."
, " For example, use and adapt 'com.example.package'."
Expand Down
2 changes: 1 addition & 1 deletion hs-bindgen/src-internal/HsBindgen/Frontend.hs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ frontend tracer FrontendConfig{..} BootArtefact{..} = do

-- Omitted types
frontendOmitTypes <- cache "frontendOmitTypes" $
Map.elems . view ( #unitAnn % #declIndex % #omitted ) <$>
Map.elems . DeclIndex.getOmitted . view ( #unitAnn % #declIndex) <$>
resolveBindingSpecsPass

-- Declarations.
Expand Down
Loading
Loading