Skip to content

Commit

Permalink
Cairo v0.11.1a0 (pre).
Browse files Browse the repository at this point in the history
  • Loading branch information
liorgold2 committed May 7, 2023
1 parent c954f15 commit 9736ef9
Show file tree
Hide file tree
Showing 310 changed files with 6,757 additions and 5,518 deletions.
20 changes: 20 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
load("vars.bzl", "ADDITIONAL_IMPORTS")

exports_files([
".clang-format",
"package.json",
"yarn_ganache.lock",
] + glob(["*.py"]))

# The 'starkware' library adds 'src' to PYTHONPATH.
# The library on its own does not add any dependencies.
# This library is needed to allow us to use "import starkware.foo" instead of
# "import src.starkware.foo".
py_library(
name = "starkware",
srcs = [],
imports = [
"src",
] + ADDITIONAL_IMPORTS,
visibility = ["//visibility:public"],
)
22 changes: 0 additions & 22 deletions CMakeLists.txt

This file was deleted.

25 changes: 11 additions & 14 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,29 +1,26 @@
FROM ciimage/python:3.9

RUN apt update
RUN apt install -y make libgmp3-dev g++ python3-pip python3.9-dev python3.9-venv npm
# Installing cmake via apt doesn't bring the most up-to-date version.
RUN pip install cmake==3.22
COPY ./docker_common_deps.sh /app/
WORKDIR /app/
RUN ./docker_common_deps.sh
RUN apt-get install -y git libgmp3-dev python3-pip python3.9-venv python3.9-dev npm

# Install solc and ganache
RUN curl https://binaries.soliditylang.org/linux-amd64/solc-linux-amd64-v0.6.12+commit.27d51765 -o /usr/local/bin/solc-0.6.12
RUN echo 'f6cb519b01dabc61cab4c184a3db11aa591d18151e362fcae850e42cffdfb09a /usr/local/bin/solc-0.6.12' | sha256sum --check
RUN chmod +x /usr/local/bin/solc-0.6.12
RUN npm install -g --unsafe-perm [email protected]

COPY . /app/

# Build.
WORKDIR /app/
RUN ./build.sh
COPY . /app

WORKDIR /app/build/Release
RUN make all -j8
# Build the cairo-lang package.
RUN bazel build //src/starkware/cairo/lang:create_cairo_lang_package_zip
RUN build/bazelbin/src/starkware/cairo/lang/create_cairo_lang_package_zip

# Run tests.
RUN ctest -V -j8
# Build and test all the targets.
RUN bazel build //...
RUN bazel test //...

WORKDIR /app/
RUN src/starkware/cairo/lang/package_test/run_test.sh

# Build the Visual Studio Code extension.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Once the docker image is built, you can fetch the python package zip file using:

```bash
> container_id=$(docker create cairo)
> docker cp ${container_id}:/app/cairo-lang-0.11.0.2.zip .
> docker cp ${container_id}:/app/cairo-lang-0.11.1.zip .
> docker rm -v ${container_id}
```

89 changes: 89 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive", "http_file")
load("//bazel_utils:get_from_cairo_lang.bzl", "get_from_cairo_lang")

http_archive(
name = "build_bazel_rules_nodejs",
sha256 = "f10a3a12894fc3c9bf578ee5a5691769f6805c4be84359681a785a0c12e8d2b6",
urls = [
"https://github.com/bazelbuild/rules_nodejs/releases/download/5.5.3/rules_nodejs-5.5.3.tar.gz",
],
)

load("@build_bazel_rules_nodejs//:repositories.bzl", "build_bazel_rules_nodejs_dependencies")

build_bazel_rules_nodejs_dependencies()

load("@build_bazel_rules_nodejs//:index.bzl", "yarn_install")

yarn_install(
name = "npm_ganache",
package_json = "//:package.json",
yarn_lock = "//:yarn_ganache.lock",
)

http_file(
name = "solc-0.6.12",
downloaded_file_path = "solc-0.6.12",
executable = True,
sha256 = "f6cb519b01dabc61cab4c184a3db11aa591d18151e362fcae850e42cffdfb09a",
urls = [
"https://binaries.soliditylang.org/linux-amd64/solc-linux-amd64-v0.6.12+commit.27d51765",
"https://starkware-third-party.s3.us-east-2.amazonaws.com/ethereum/solc-0.6.12",
],
)

http_archive(
name = "rules_python",
sha256 = "a3a6e99f497be089f81ec082882e40246bfd435f52f4e82f37e89449b04573f6",
strip_prefix = "rules_python-0.10.2",
url = "https://github.com/bazelbuild/rules_python/archive/refs/tags/0.10.2.tar.gz",
)

http_archive(
name = "cairo-compiler-archive-1.0.0",
build_file = get_from_cairo_lang("//src/starkware/starknet/compiler/v1:BUILD.cairo-compiler-archive-1.0.0"),
strip_prefix = "cairo",
url = "https://github.com/starkware-libs/cairo/releases/download/v1.0.0-rc0/release-x86_64-unknown-linux-musl.tar.gz",
)

http_archive(
name = "pypy3.9",
build_file = "//:pypy3.9_archive_build_file.bzl",
sha256 = "46818cb3d74b96b34787548343d266e2562b531ddbaf330383ba930ff1930ed5",
strip_prefix = "pypy3.9-v7.3.9-linux64",
url = "https://downloads.python.org/pypy/pypy3.9-v7.3.9-linux64.tar.bz2",
)

register_toolchains("//bazel_utils/python:py_stub_toolchain")

load("@rules_python//python:repositories.bzl", "python_register_toolchains")

python_register_toolchains(
name = "python3",
python_version = "3.9",
register_toolchains = False,
)

# Install python pip packages in a lazy way.
load("@python3//:defs.bzl", "interpreter")
load("@rules_python//python:pip.bzl", "pip_parse")

pip_parse(
name = "cpython_reqs",
python_interpreter_target = interpreter,
requirements_lock = "//scripts:requirements.txt",
)

load("@cpython_reqs//:requirements.bzl", "install_deps")

install_deps()

pip_parse(
name = "pypy_reqs",
python_interpreter_target = "@pypy3.9//:bin/pypy3",
requirements_lock = "//scripts:pypy-requirements.txt",
)

load("@pypy_reqs//:requirements.bzl", pypy_install_deps = "install_deps")

pypy_install_deps()
37 changes: 37 additions & 0 deletions bazel_utils/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
load("//bazel_utils:python.bzl", "py_exe")

package(default_visibility = ["//visibility:public"])

exports_files(["pytest_wrapper.py"])

py_binary(
name = "gen_python_exe",
srcs = ["gen_python_exe.py"],
main = "gen_python_exe.py",
)

py_binary(
name = "solc_wrapper",
srcs = ["solc_wrapper.py"],
)

sh_binary(
name = "solc-0.6.12",
srcs = ["@solc-0.6.12//file"],
)

py_library(
name = "default_extract_artifacts_lib",
srcs = [
"__init__.py",
"extract_artifacts.py",
],
visibility = ["//visibility:public"],
deps = [],
)

py_exe(
name = "default_extract_artifacts_exe",
module = "bazel_utils.extract_artifacts",
deps = ["default_extract_artifacts_lib"],
)
42 changes: 39 additions & 3 deletions bazel_utils/gen_python_exe.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,24 @@ def main():
parser = ArgumentParser(description="Generates an executable file for py_exe().")
parser.add_argument("--name", help="The name of the target", required=True)
parser.add_argument("--module", help="The name of the module to run", required=True)
parser.add_argument(
"--py_binary_path",
help="Path where the py_binary is defined by Bazel. For rlocation",
required=True,
)
parser.add_argument(
"--output_py", help="Path for the output of the python module", required=True
)
parser.add_argument(
"--output_sh",
help="Path for the output of the shell binary that wraps the py_binary",
required=True,
)
args = parser.parse_args()

print(
f"""\
with open(args.output_py, "w") as f:
f.write(
f"""\
import os
import subprocess
import sys
Expand All @@ -26,7 +40,29 @@ def main():
proc = subprocess.run(cmd)
sys.exit(proc.returncode)
"""
)
)

with open(args.output_sh, "w") as f:
f.write(
f"""\
#!/bin/bash
# --- begin runfiles.bash initialization v2 ---
# Copy-pasted from the Bazel Bash runfiles library v2.
set -uo pipefail; f=bazel_tools/tools/bash/runfiles/runfiles.bash
source "${{RUNFILES_DIR:-/dev/null}}/$f" 2>/dev/null || \
source "$(grep -sm1 "^$f " "${{RUNFILES_MANIFEST_FILE:-/dev/null}}" | cut -f2- -d' ')" \
2>/dev/null || \
source "$0.runfiles/$f" 2>/dev/null || \
source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
{{ echo>&2 "ERROR: cannot find $f"; exit 1; }}; f=; set -e
# --- end runfiles.bash initialization v2 ---
unset PYTHONPATH
exec $(rlocation {args.py_binary_path}) "$@"
"""
)


if __name__ == "__main__":
Expand Down
2 changes: 2 additions & 0 deletions bazel_utils/get_from_cairo_lang.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def get_from_cairo_lang(label):
return label
Loading

0 comments on commit 9736ef9

Please sign in to comment.