{"id":15108500,"url":"https://github.com/dropbox/djinni","last_synced_at":"2025-12-17T07:27:29.687Z","repository":{"id":20527239,"uuid":"23806326","full_name":"dropbox/djinni","owner":"dropbox","description":"A tool for generating cross-language type declarations and interface bindings.","archived":true,"fork":false,"pushed_at":"2020-03-26T04:02:08.000Z","size":3865,"stargazers_count":2882,"open_issues_count":77,"forks_count":488,"subscribers_count":139,"default_branch":"master","last_synced_at":"2025-01-17T18:36:27.142Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dropbox.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-09-08T20:09:32.000Z","updated_at":"2025-01-09T05:10:47.000Z","dependencies_parsed_at":"2022-07-07T14:31:43.436Z","dependency_job_id":null,"html_url":"https://github.com/dropbox/djinni","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/dropbox/djinni","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dropbox%2Fdjinni","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dropbox%2Fdjinni/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dropbox%2Fdjinni/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dropbox%2Fdjinni/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dropbox","download_url":"https://codeload.github.com/dropbox/djinni/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dropbox%2Fdjinni/sbom","scorecard":{"id":356708,"data":{"date":"2025-08-11","repo":{"name":"github.com/dropbox/djinni","commit":"4f3aa6971b2b539cfadec4df2243a268651c4de3"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3.2,"checks":[{"name":"Code-Review","score":8,"reason":"Found 24/30 approved changesets -- score normalized to 8","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Maintained","score":0,"reason":"project is archived","details":["Warn: Repository is archived."],"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Binary-Artifacts","score":5,"reason":"binaries present in source code","details":["Warn: binary detected: deps/java/jsr305-3.0.0.jar:1","Warn: binary detected: deps/java/test/hamcrest-core-1.3.jar:1","Warn: binary detected: deps/java/test/junit-4.11.jar:1","Warn: binary detected: example/android/gradle/wrapper/gradle-wrapper.jar:1","Warn: binary detected: src/support/sbt-launch.jar:1"],"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: Apache License 2.0: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: containerImage not pinned by hash: example/localhost/Dockerfile:1: pin your Docker image by updating ubuntu:vivid to ubuntu:vivid@sha256:16aaeb60ca8cee4ced9952fb89e020295a340e8507e25a9d7023265ece529018","Warn: containerImage not pinned by hash: test-suite/java/docker/centos_6/Dockerfile:1: pin your Docker image by updating centos:6 to centos:6@sha256:a93df2e96e07f56ea48f215425c6f1673ab922927894595bb5c0ee4c5a955133","Warn: containerImage not pinned by hash: test-suite/java/docker/debian_jessie/Dockerfile:1: pin your Docker image by updating debian:jessie to debian:jessie@sha256:32ad5050caffb2c7e969dac873bce2c370015c2256ff984b70c1c08b3a2816a0","Warn: containerImage not pinned by hash: test-suite/java/docker/fedora_24/Dockerfile:1: pin your Docker image by updating fedora:24 to fedora:24@sha256:0c1580c63e623ecfa0ef2d4a548d73a655e8072725bcca01bc6f2e446914a7bc","Warn: containerImage not pinned by hash: test-suite/java/docker/ubuntu_trusty/Dockerfile:1: pin your Docker image by updating ubuntu:trusty to ubuntu:trusty@sha256:64483f3496c1373bfd55348e88694d1c4d0c9b660dee6bfef5e12f43b9933b30","Warn: containerImage not pinned by hash: test-suite/java/docker/ubuntu_utopic/Dockerfile:1: pin your Docker image by updating ubuntu:utopic-20150625 to ubuntu:utopic-20150625@sha256:a19a9f448997588d8d14817f3ef34f8dc7651b0df2b79c942115f64572eb7c65","Info:   0 out of   6 containerImage dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 24 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-18T09:46:38.374Z","repository_id":20527239,"created_at":"2025-08-18T09:46:38.374Z","updated_at":"2025-08-18T09:46:38.374Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":277200296,"owners_count":25778129,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-27T02:00:08.978Z","response_time":73,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-09-25T22:02:11.086Z","updated_at":"2025-09-27T07:31:05.789Z","avatar_url":"https://github.com/dropbox.png","language":"C++","readme":"# Djinni\n\nDjinni is a tool for generating cross-language type declarations and interface bindings. It's\ndesigned to connect C++ with either Java or Objective-C. Python support is available in an\nexperimental version on the `python` branch.\n\nDjinni can be used to interface cross-platform C++ library code with platform-specific Java and\nObjective-C on Android and iOS.  We announced Djinni at CppCon 2014. You can see the\n[slides](https://bit.ly/djinnitalk) and [video](https://bit.ly/djinnivideo).  For more info about\nDjinni and how others are using it, check out the community links at the end of this document.\n\n__Maintenance note:__ This repo is stable but no longer maintained by Dropbox.  If you have\nquestions or want to talk to other users of Djinni, you can join the Slack community via the\nlink at the end of this document.\n\n## Main Features\n- Generates parallel C++, Java and Objective-C type definitions from a single interface\n  description file.\n- Supports the intersection of the three core languages' primitive types, and user-defined\n  enums, records, and interfaces.\n- Generates interface code allowing bidirectional calls between C++ and Java (with JNI) or\n  Objective-C (with Objective-C++).\n- Can autogenerate comparator functions (equality, ordering) on data types.\n\n## Getting Started\n\n### Types\nDjinni generates code based on interface definitions in an IDL file. An IDL file can contain\nthree kinds of declarations: enums, records, and interfaces.\n\n* Enums become C++ enum classes, Java enums, or ObjC `NS_ENUM`s.\n* Flags become C++ enum classes with convenient bit-oriented operators, Java enums with `EnumSet`, or ObjC `NS_OPTIONS`.\n* Records are pure-data value objects.\n* Interfaces are objects with defined methods to call (in C++, passed by `shared_ptr`). Djinni\n  produces code allowing an interface implemented in C++ to be transparently used from ObjC or\n  Java, and vice versa.\n\n### IDL Files\nDjinni's input is an interface description file. Here's an example:\n\n    # Multi-line comments can be added here. This comment will be propagated\n    # to each generated definition.\n    my_enum = enum {\n        option1;\n        option2;\n        option3;\n    }\n\n    my_flags = flags {\n      flag1;\n      flag2;\n      flag3;\n      no_flags = none;\n      all_flags = all;\n    }\n\n    my_record = record {\n        id: i32;\n        info: string;\n        store: set\u003cstring\u003e;\n        hash: map\u003cstring, i32\u003e;\n\n        values: list\u003canother_record\u003e;\n\n        # Comments can also be put here\n\n        # Constants can be included\n        const string_const: string = \"Constants can be put here\";\n        const min_value: another_record = {\n            key1 = 0,\n            key2 = \"\"\n        };\n    }\n\n    another_record = record {\n        key1: i32;\n        key2: string;\n    } deriving (eq, ord)\n\n    # This interface will be implemented in C++ and can be called from any language.\n    my_cpp_interface = interface +c {\n        method_returning_nothing(value: i32);\n        method_returning_some_type(key: string): another_record;\n        static get_version(): i32;\n\n        # Interfaces can also have constants\n        const version: i32 = 1;\n    }\n\n    # This interface will be implemented in Java and ObjC and can be called from C++.\n    my_client_interface = interface +j +o {\n        log_string(str: string): bool;\n    }\n\nDjinni files can also include each other. Adding the line:\n\n    @import \"relative/path/to/filename.djinni\"\n\nat the beginning of a file will simply include another file. Child file paths are\nrelative to the location of the file that contains the @import. Two different djinni files\ncannot define the same type. `@import` behaves like `#include` with `#pragma once` in C++, or\nlike ObjC's `#import`: if a file is included multiple times through different paths, then it\nwill only be processed once.\n\n### Generate Code\nWhen the Djinni file(s) are ready, from the command line or a bash script you can run:\n\n    src/run \\\n       --java-out JAVA_OUTPUT_FOLDER \\\n       --java-package com.example.jnigenpackage \\\n       --java-cpp-exception DbxException \\ # Choose between a customized C++ exception in Java and java.lang.RuntimeException (the default).\n       --ident-java-field mFooBar \\ # Optional, this adds an \"m\" in front of Java field names\n       \\\n       --cpp-out CPP_OUTPUT_FOLDER \\\n       \\\n       --jni-out JNI_OUTPUT_FOLDER \\\n       --ident-jni-class NativeFooBar \\ # This adds a \"Native\" prefix to JNI class\n       --ident-jni-file NativeFooBar \\ # This adds a prefix to the JNI filenames otherwise the cpp and jni filenames are the same.\n       \\\n       --objc-out OBJC_OUTPUT_FOLDER \\\n       --objc-type-prefix DB \\ # Apple suggests Objective-C classes have a prefix for each defined type.\n       \\\n       --objcpp-out OBJC_OUTPUT_FOLDER \\\n       \\\n       --idl MY_PROJECT.djinni\n\nSome other options are also available, such as `--cpp-namespace` that put generated C++ code into the namespace specified. For a list of all options, run\n`src/run --help`\n\nSample generated code is in the `example/generated-src/` and `test-suite/generated-src/`\ndirectories of this distribution.\n\nNote that if a language's output folder is not specified, that language will not be generated.\nFor more information, run `run --help` to see all command line arguments available.\n\n### Use Generated Code in Your Project\n\n#### Java / JNI / C++ Project\n\n##### Includes \u0026 Build target\nThe following headers / code will be generated for each defined type:\n\n| Type       | C++ header             | C++ source                 | Java                | JNI header            | JNI source            |\n|------------|------------------------|----------------------------|---------------------|-----------------------|-----------------------|\n| Enum/Flags | my\\_enum.hpp           |                            | MyEnum.java         | NativeMyEnum.hpp      | NativeMyEnum.cpp      |\n| Record     | my\\_record[\\_base].hpp | my\\_record[\\_base].cpp (+) | MyRecord[Base].java | NativeMyRecord.hpp    | NativeMyRecord.cpp    |\n| Interface  | my\\_interface.hpp      | my\\_interface.cpp (+)      | MyInterface.java    | NativeMyInterface.hpp | NativeMyInterface.cpp |\n\n(+) Generated only for types that contain constants.\n\nAdd all generated source files to your build target, as well as the contents of\n`support-lib/java`.\n\n##### Our JNI approach\nJNI stands for Java Native Interface, an extension of the Java language to allow interop with\nnative (C/C++) code or libraries. Complete documentation on JNI is available at:\nhttp://docs.oracle.com/javase/6/docs/technotes/guides/jni/spec/jniTOC.html\n\nFor each type, built-in (`list`, `string`, etc.) or user-defined, Djinni produces a translator\nclass with a `toJava` and `fromJava` function to translate back and forth.\n\nApplication code is responsible for the initial load of the JNI library. Add a static block\nsomewhere in your code:\n\n    System.loadLibrary(\"YourLibraryName\");\n    // The name is specified in Android.mk / build.gradle / Makefile, depending on your build system.\n\nIf you package your native library in a jar, you can also use `com.dropbox.djinni.NativeLibLoader` \nto help unpack and load your lib(s).  See the [Localhost README](example/localhost/README.md)\nfor details.\n\nWhen a native library is called, JNI calls a special function called `JNI_OnLoad`. If you use\nDjinni for all JNI interface code, include `support_lib/jni/djinni_main.cpp`; if not,\nyou'll need to add calls to your own `JNI_OnLoad` and `JNI_OnUnload` functions. See\n`support-lib/jni/djinni_main.cpp` for details.\n\n#### Objective-C / C++ Project\n\n##### Includes \u0026 Build Target\nGenerated files for Objective-C / C++ are as follows (assuming prefix is `DB`):\n\n| Type       | C++ header             | C++ source                 | Objective-C files        | Objective-C++ files         |\n|------------|------------------------|----------------------------|--------------------------|-----------------------------|\n| Enum/Flags | my\\_enum.hpp           |                            | DBMyEnum.h               |                             |\n| Record     | my\\_record[\\_base].hpp | my\\_record[\\_base].cpp (+) | DBMyRecord[Base].h       | DBMyRecord[Base]+Private.h  |\n|            |                        |                            | DBMyRecord[Base].mm (++) | DBMyRecord[Base]+Private.mm |\n| Interface  | my\\_interface.hpp      | my\\_interface.cpp (+)      | DBMyInterface.h          | DBMyInterface+Private.h     |\n|            |                        |                            |                          | DBMyInterface+Private.mm    |\n\n(+) Generated only for types that contain constants.\n(++) Generated only for types with derived operations and/or constants. These have `.mm` extensions to allow non-trivial constants.\n\nAdd all generated files to your build target, as well as the contents of `support-lib/objc`.\nNote that `+Private` files can only be used with ObjC++ source (other headers are pure ObjC) and are not required by Objective-C users of your interface.\n\n## Details of Generated Types\n### Enum\nEnums are translated to C++ `enum class`es with underlying type `int`, ObjC `NS_ENUM`s with\nunderlying type `NSInteger`, and Java enums.\n\n### Flags\nFlags are translated to C++ `enum class`es with underlying type `unsigned` and a generated set\nof overloaded bitwise operators for convenience, ObjC `NS_OPTIONS` with underlying type\n`NSUInteger`, and Java `EnumSet\u003c\u003e`. Contrary to the above enums, the enumerants of flags represent\nsingle bits instead of integral values.\n\nWhen specifying a `flags` type in your IDL file you can assign special semantics to options:\n\n```\nmy_flags = flags {\n  flag1;\n  flag2;\n  flag3;\n  no_flags = none;\n  all_flags = all;\n}\n```\nIn the above example the elements marked with `none` and `all` are given special meaning.\nIn C++ and ObjC the `no_flags` option is generated with a value that has no bits set (i.e. `0`),\nand `all_flags` is generated as a bitwise-or combination of all other values. In Java these\nspecial options are not generated as one can just use `EnumSet.noneOf()` and `EnumSet.allOf()`.\n\n### Record\nRecords are data objects. In C++, records contain all their elements by value, including other\nrecords (so a record cannot contain itself).\n\n#### Data types\nThe available data types for a record, argument, or return value are:\n\n - Boolean (`bool`)\n - Primitives (`i8`, `i16`, `i32`, `i64`, `f32`, `f64`).\n - Strings (`string`)\n - Binary (`binary`). This is implemented as `std::vector\u003cuint8_t\u003e` in C++, `byte[]` in Java,\n   and `NSData` in Objective-C.\n - Date (`date`).  This is `chrono::system_clock::time_point` in C++, `Date` in Java, and\n   `NSDate` in Objective-C.\n - List (`list\u003ctype\u003e`). This is `vector\u003cT\u003e` in C++, `ArrayList` in Java, and `NSArray`\n   in Objective-C. Primitives in a list will be boxed in Java and Objective-C.\n - Set (`set\u003ctype\u003e`). This is `unordered_set\u003cT\u003e` in C++, `HashSet` in Java, and `NSSet` in\n   Objective-C. Primitives in a set will be boxed in Java and Objective-C.\n - Map (`map\u003ctypeA, typeB\u003e`). This is `unordered_map\u003cK, V\u003e` in C++, `HashMap` in Java, and\n   `NSDictionary` in Objective-C. Primitives in a map will be boxed in Java and Objective-C.\n - Enumerations / Flags\n - Optionals (`optional\u003ctypeA\u003e`). This is `std::experimental::optional\u003cT\u003e` in C++11, object /\n   boxed primitive reference in Java (which can be `null`), and object / NSNumber strong\n   reference in Objective-C (which can be `nil`).\n - Other record types. This is generated with a by-value semantic, i.e. the copy method will\n   deep-copy the contents.\n\n#### Extensions\nTo support extra fields and/or methods, a record can be \"extended\" in any language. To extend\na record in a language, you can add a `+c` (C++), `+j` (Java), or `+o` (ObjC) flag after the\nrecord tag. The generated type will have a `Base` suffix, and you should create a derived type\nwithout the suffix that extends the record type.\n\nThe derived type must be constructible in the same way as the `Base` type. Interfaces will\nalways use the derived type.\n\n#### Derived methods\nFor record types, Haskell-style \"deriving\" declarations are supported to generate some common\nmethods. Djinni is capable of generating equality and order comparators, implemented\nas operator overloading in C++ and standard comparison functions in Java / Objective-C.\n\nThings to note:\n\n - All fields in the record are compared in the order they appear in the record declaration.\n   If you need to add a field later, make sure the order is correct.\n - Ordering comparison is not supported for collection types, optionals, and booleans.\n - To compare records containing other records, the inner record must derive at least the same\n   types of comparators as the outer record.\n\n### Interface\n\n#### Special Methods for C++ Only\n`+c` interfaces (implementable only in C++) can have methods flagged with the special keywords const and static which have special effects in C++:\n\n   special_methods = interface +c {\n       const accessor_method();\n       static factory_method();\n   }\n   \n- `const` methods will be declared as const in C++, though this cannot be enforced on callers in other languages, which lack this feature.\n- `static` methods will become a static method of the C++ class, which can be called from other languages without an object.  This is often useful for factory methods to act as a cross-language constructor.\n\n#### Exception Handling\nWhen an interface implemented in C++ throws a `std::exception`, it will be translated to a\n`java.lang.RuntimeException` in Java or an `NSException` in Objective-C. The `what()` message\nwill be translated as well.\n\n### Constants\nConstants can be defined within interfaces and records. In Java and C++ they are part of the\ngenerated class; and in Objective-C, constant names are globals with the name of the\ninterface/record prefixed. Example:\n\n   record_with_const = record +c +j +o {\n       const const_value: i32 = 8;\n   }\n\nwill be `RecordWithConst::CONST_VALUE` in C++, `RecordWithConst.CONST_VALUE` in Java, and\n`RecordWithConstConstValue` in Objective-C.\n\n## Modularization and Library Support\nWhen generating the interface for your project and wish to make it available to other users\nin all of C++/Objective-C/Java you can tell Djinni to generate a special YAML file as part\nof the code generation process. This file then contains all the information Djinni requires\nto include your types in a different project. Instructing Djinni to create these YAML files\nis controlled by the following arguments:\n- `--yaml-out`: The output folder for YAML files (Generator disabled if unspecified).\n- `--yaml-out-file`: If specified all types are merged into a single YAML file instead of generating one file per type (relative to `--yaml-out`).\n- `--yaml-prefix`: The prefix to add to type names stored in YAML files (default: `\"\"`).\n\nSuch a YAML file looks as follows:\n```yml\n---\nname: mylib_record1\ntypedef: 'record +c deriving(eq, ord)'\nparams: []\nprefix: 'mylib'\ncpp:\n    typename: '::mylib::Record1'\n    header: '\"MyLib/Record1.hpp\"'\n    byValue: false\nobjc:\n    typename: 'MLBRecord1'\n    header: '\"MLB/MLBRecord1.h\"'\n    boxed: 'MLBRecord1'\n    pointer: true\n    hash: '%s.hash'\nobjcpp:\n    translator: '::mylib::djinni::objc::Record1'\n    header: '\"mylib/djinni/objc/Record1.hpp\"'\njava:\n    typename: 'com.example.mylib.Record1'\n    boxed: 'com.example.mylib.Record1'\n    reference: true\n    generic: true\n    hash: '%s.hashCode()'\njni:\n    translator: '::mylib::djinni::jni::Record1'\n    header: '\"Duration-jni.hpp\"'\n    typename: jobject\n    typeSignature: 'Lcom/example/mylib/Record1;'\n---\nname: mylib_interface1\ntypedef: 'interface +j +o'\n    (...)\n---\nname: mylib_enum1\ntypedef: 'enum'\n    (...)\n\n```\nEach document in the YAML file describes one extern type.\nA full documentation of all fields is available in `example/example.yaml`. You can also check\nthe files `test-suite/djinni/date.yaml` and `test-suite/djinni/duration.yaml` for some\nreal working examples of what you can do with it.\n\nTo use a library type in your project simply include it in your IDL file and refer to it using\nits name identifier:\n```\n@extern \"mylib.yaml\"\n\nclient_interface = interface +c {\n  foo(): mylib_record1;\n}\n```\n\nThese files can be created by hand as long as you follow the required format. This allows you\nto support types not generated by Djinni. See `test-suite/djinni/duration.yaml` and the\naccompanying translators in `test-suite/handwritten-src/cpp/Duration-objc.hpp` and \n`test-suite/handwritten-src/cpp/Duration-jni.hpp` for an advanced example. Handwritten\ntranslators implement the following concept:\n```cpp\n// For C++ \u003c-\u003e Objective-C\nstruct Record1\n{\n    using CppType = ::mylib::Record1;\n    using ObjcType = MLBRecord1*;\n\n    static CppType toCpp(ObjcType o) { return /* your magic here */; }\n    static ObjcType fromCpp(CppType c) { return /* your magic here */; }\n\n    // Option 1: use this if no boxing is required\n    using Boxed = Record1;\n    // Option 2: or this if you do need dedicated boxing behavior\n    struct Boxed\n    {\n        using ObjcType = MLBRecord1Special*;\n        static CppType toCpp(ObjcType o) { return /* your magic here */; }\n        static ObjcType fromCpp(CppType c) { return /* your magic here */; }\n    }\n};\n```\n```cpp\n// For C++ \u003c-\u003e JNI\n#include \"djinni_support.hpp\"\nstruct Record1\n{\n    using CppType = ::mylib::Record1;\n    using JniType = jobject;\n\n    static CppType toCpp(JniType j) { return /* your magic here */; }\n    // The return type *must* be LocalRef\u003cT\u003e if T is not a primitive!\n    static ::djinni::LocalRef\u003cjobject\u003e JniType fromCpp(CppType c) { return /* your magic here */; }\n\n    using Boxed = Record1;\n};\n```\nFor `interface` classes the `CppType` alias is expected to be a `std::shared_ptr\u003cT\u003e`.\n\nBe sure to put the translators into representative and distinct namespaces.\n\nIf your type is generic the translator takes the same number of template parameters.\nAt usage each is instantiated with the translators of the respective type argument.\n```cpp\ntemplate\u003cclass A, class B\u003e\nstruct Record1\n{\n    using CppType = ::mylib::Record1\u003ctypename A::CppType, typename B::CppType\u003e;\n    using ObjcType = MLBRecord1*;\n\n    static CppType toCpp(ObjcType o)\n    {\n        // Use A::toCpp() and B::toCpp() if necessary\n        return /* your magic here */;\n    }\n    static ObjcType fromCpp(CppType c)\n    {\n        // Use A::fromCpp() and B::fromCpp() if necessary\n        return /* your magic here */;\n    }\n\n    using Boxed = Record1;\n};\n```\n\n## Miscellaneous\n### Record constructors / initializers\nDjinni does not permit custom constructors for records or interfaces, since there would be\nno way to implement them in Java except by manually editing the autogenerated file. Instead,\nuse extended records or static functions.\n\n### Identifier Format\nDjinni supports overridable formats for most generated filenames and identifiers. The complete\nlist can found by invoking Djinni with `--help`. The format is specified by formatting the\nword FooBar in the desired style:\n- `FOO_BAR` -\u003e `GENERATED_IDENT`\n- `mFooBar` -\u003e `mGeneratedIdent`\n- `FooBar` -\u003e `GeneratedIdent`\n\n### Integer types\nIn Djinni, i8 through i64 are all used with fixed length. The C++ builtin `int`, `long`, etc\nand Objective-C `NSInteger` are not used because their length varies by architecture. Unsigned\nintegers are not included because they are not available in Java.\n\n## Test Suite\nRun `make test` to invoke the test suite, found in the test-suite subdirectory. It will build and run Java code on a local JVMy, plus Objective-C on an iOS simulator.  The latter will only work on a Mac with Xcode.\n\n## Generate a standalone jar\n\nThe `djinni_jar` target of the main `Makefile` creates a standalone `.jar`. \nThis uses the [sbt assembly plugin](https://github.com/sbt/sbt-assembly) under the hoods.\n\nSimply call this target from the root directory:\n```shell\nmake djinni_jar\n```\nThis will produce a `.jar` file inside the `src/target/scala_\u003cSCALA_VERSION\u003e/djinni-assembly-\u003cVERSION\u003e.jar`.\n\nYou can move and use it as any other executable `.jar`.\n\nAssuming the `.jar` is located at `$DJINNI_JAR_DIR` its version equals `0.1-SNAPSHOT`:\n```shell\n# Example\njava -jar $DJINNI_JAR_DIR/djinni-assembly-0.1-SNAPSHOT.jar \\\n    --java-out \"$temp_out/java\" \\\n    --java-package $java_package \\\n    --java-class-access-modifier \"package\" \\\n    --java-nullable-annotation \"javax.annotation.CheckForNull\" \\\n    --java-nonnull-annotation \"javax.annotation.Nonnull\" \\\n    --ident-java-field mFooBar \\\n    \\\n    --cpp-out \"$temp_out/cpp\" \\\n    --cpp-namespace textsort \\\n    --ident-cpp-enum-type foo_bar \\\n    \\\n    --jni-out \"$temp_out/jni\" \\\n    --ident-jni-class NativeFooBar \\\n    --ident-jni-file NativeFooBar \\\n    \\\n    --objc-out \"$temp_out/objc\" \\\n    --objcpp-out \"$temp_out/objc\" \\\n    --objc-type-prefix TXS \\\n    --objc-swift-bridging-header \"TextSort-Bridging-Header\" \\\n    \\\n    --idl \"$in\"\n```\n\n*Note*: The `all` target of the main `Makefile` includes the `djinni_jar` target.\n\n## Generate an iOS universal binary of the support library.\n\nThe `ios-build-support-lib.sh` helps you to build an universal static library for iOS platforms.\nIt uses the platform file of the [ios-cmake](https://github.com/leetal/ios-cmake) repository.\n\nIt basically creates one universal static library per `IOS_PLATFORM` variable and uses `lipo` \nto merge all the files in one.\n\nThere is basically two variables you would like to modify:\n\n- `BUILD_APPLE_ARCHITECTURES`: Specifies which `IOS_PLATFORM` to build.\nFor more informations, take a look at https://github.com/leetal/ios-cmake.\n\n- `ENABLE_BITCODE`: enable/disable the bitcode generation.\n\n## Android Parcelable records\n\nDjinni supports generating records that implements `android.os.parcelable`.\n\nIn order to do that, there are two steps needed:\n- deriving the records that should be parcelable with the keyword parcelable: `deriving(parcelable)`\n- run Djinni with the following flag `--java-implement-android-os-parcelable true`\n\n## Community Links\n\n* Join the discussion with other developers at the [Mobile C++ Slack Community](https://mobilecpp.herokuapp.com/)\n* There are a set of [tutorials](http://mobilecpptutorials.com/) for building a cross-platform app using Djinni.\n* [mx3](https://github.com/libmx3/mx3) is an example project demonstrating use of Djinni and other tools.\n* [Slides](https://bit.ly/djinnitalk) and [video](https://bit.ly/djinnivideo) from the CppCon 2014 talk where we introduced Djinni.\n* [Slides](https://bit.ly/djinnitalk2) and [video](https://bit.ly/djinnivideo2) from the CppCon 2015 talk about Djinni implementation techniques, and the addition of Python.\n* You can see a [CppCon 2014 talk](https://www.youtube.com/watch?v=5AZMEm3rZ2Y) by app developers at Dropbox about their cross-platform experiences.\n\n## Authors\n- Kannan Goundan\n- Tony Grue\n- Derek He\n- Steven Kabbes\n- Jacob Potter\n- Iulia Tamas\n- Andrew Twyman\n\n## Contacts\n- Andrew Twyman - `artwymana+djinni@gmail.com`\n- Jacob Potter - `djinni@j4cbo.com`\n","funding_links":[],"categories":["正则表达式","etc","Scripting"],"sub_categories":["脚本"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdropbox%2Fdjinni","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdropbox%2Fdjinni","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdropbox%2Fdjinni/lists"}