Skip to content

Commit

Permalink
wrap example (#100)
Browse files Browse the repository at this point in the history
Summary:
example use of type level module aliases technique to implement `-pack`.

Pull Request resolved: #100

Test Plan: `buck2 build root//ocaml/wrap:test-mylib`

Reviewed By: ndmitchell

Differential Revision: D43811509

Pulled By: shayne-fletcher

fbshipit-source-id: 695f47894bb8b7bdc234295731a9dbbbbf91ab6f
  • Loading branch information
shayne-fletcher authored and facebook-github-bot committed Mar 6, 2023
1 parent 7311298 commit e145228
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 0 deletions.
48 changes: 48 additions & 0 deletions examples/prelude/ocaml/wrap/BUCK
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# @lint-ignore-every BUCKFORMAT

# buildifier: disable=no-effect
ocaml_library(
name = "_mylib",
compiler_flags = [
"-no-alias-deps",
"-w", "-49",
],
srcs = [
"mylib.mli",
"mylib.ml",
],
visibility = [ "PUBLIC" ],
) if not host_info().os.is_windows else None

export_file(
name= "mylib.mli",
src = "mylib.mli"
)

# buildifier: disable=no-effect
ocaml_library(
name = "mylib",
ocamldep_flags = [
"-open", "Mylib",
"-map", "$(location :mylib.mli)"
],
compiler_flags = [
"-no-alias-deps",
"-w", "-49",
"-open", "Mylib"
],
srcs = [
"mylib__A.ml",
"mylib__B.ml",
],
deps = [ ":_mylib" ],
visibility = [ "PUBLIC" ],
) if not host_info().os.is_windows else None

# buildifier: disable=no-effect
ocaml_binary(
name = "test-mylib",
srcs = [ "test_Mylib.ml" ] ,
deps = [ ":mylib" ],
visibility = [ "PUBLIC" ],
) if not host_info().os.is_windows else None
11 changes: 11 additions & 0 deletions examples/prelude/ocaml/wrap/mylib.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
(*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under both the MIT license found in the
* LICENSE-MIT file in the root directory of this source tree and the Apache
* License, Version 2.0 found in the LICENSE-APACHE file in the root directory
* of this source tree.
*)

module A = Mylib__A
module B = Mylib__B
11 changes: 11 additions & 0 deletions examples/prelude/ocaml/wrap/mylib.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
(*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under both the MIT license found in the
* LICENSE-MIT file in the root directory of this source tree and the Apache
* License, Version 2.0 found in the LICENSE-APACHE file in the root directory
* of this source tree.
*)

module A = Mylib__A
module B = Mylib__B
10 changes: 10 additions & 0 deletions examples/prelude/ocaml/wrap/mylib__A.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
(*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under both the MIT license found in the
* LICENSE-MIT file in the root directory of this source tree and the Apache
* License, Version 2.0 found in the LICENSE-APACHE file in the root directory
* of this source tree.
*)

let print_hello () = B.print_hello ()
10 changes: 10 additions & 0 deletions examples/prelude/ocaml/wrap/mylib__B.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
(*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under both the MIT license found in the
* LICENSE-MIT file in the root directory of this source tree and the Apache
* License, Version 2.0 found in the LICENSE-APACHE file in the root directory
* of this source tree.
*)

let print_hello () = Printf.printf "Hello!\n"
10 changes: 10 additions & 0 deletions examples/prelude/ocaml/wrap/test_Mylib.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
(*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under both the MIT license found in the
* LICENSE-MIT file in the root directory of this source tree and the Apache
* License, Version 2.0 found in the LICENSE-APACHE file in the root directory
* of this source tree.
*)

let _: unit = Mylib.A.print_hello ()

0 comments on commit e145228

Please sign in to comment.