aboutsummaryrefslogtreecommitdiffstats
path: root/packages/dev-tools-pages/ts/pages/compiler.tsx
blob: 407646add23a664388b46032bae7d38ac44671fb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
import * as React from 'react';
import { hydrate, render } from 'react-dom';
import * as Loadable from 'react-loadable';

import { context } from 'ts/context/compiler';

import { Base } from 'ts/components/base';
import { Breakout } from 'ts/components/breakout';
import { CallToAction } from 'ts/components/call_to_action';
import { Code } from 'ts/components/code';
import { Compiler as CompilerComponent } from 'ts/components/compiler';
import { Content } from 'ts/components/content';
import { ContentBlock } from 'ts/components/content-block';
import { Hero } from 'ts/components/hero';
import { InlineCode } from 'ts/components/inline-code';
import { Lead } from 'ts/components/typography';

const Animation = Loadable({
    loader: () => System.import(/* webpackChunkName: 'compiler-animation' */ 'ts/components/animations/compiler'),
    loading: () => <div />,
    delay: 1000,
    render(loadable: { CompilerAnimation: any }): React.ReactNode {
        const Component = loadable.CompilerAnimation;
        return <Component />;
    },
});

const SOLIDITY_INPUT_FORMAT_DOCS =
    'https://solidity.readthedocs.io/en/v0.4.24/using-the-compiler.html#compiler-input-and-output-json-description';

const Compiler: React.StatelessComponent<{}> = () => (
    <Base context={context}>
        <Hero>
            <Animation />
        </Hero>
        <CompilerComponent />
        <Content>
            <ContentBlock main={true} title="Get started" />
            <ContentBlock title="Install">
                <Breakout>
                    <Code canCopy={true}>npm install @0x/sol-compiler --g</Code>
                </Breakout>
            </ContentBlock>

            <ContentBlock title="Run">
                <Breakout>
                    <Code canCopy={true}>cd /your_project_dir && sol-compiler</Code>
                </Breakout>
            </ContentBlock>

            <ContentBlock title="Configure">
                <p>
                    Configure via a <InlineCode>compiler.json</InlineCode> file.
                </p>
                <Breakout>
                    <Code canCopy={true}>mkdir compiler.json</Code>
                </Breakout>
                <p>Example of settings:</p>
                <Breakout>
                    <Code language="json" canCopy={true}>
                        {`{
    "contractsDir": "contracts",
    "artifactsDir": "artifacts",
    "contracts": "*",
    "compilerSettings": {
        "optimizer": { "enabled": false },
        "outputSelection": {
            "*": {
                "*": ["abi", "evm.bytecode.object"]
            }
        }
    }
}`}
                    </Code>
                </Breakout>
            </ContentBlock>
        </Content>
        <Content dark={true}>
            <ContentBlock main={true} title="Artifacts">
                <Lead>
                    Sol compiler uses{' '}
                    <a href={SOLIDITY_INPUT_FORMAT_DOCS} target="_blank">
                        Solidity standard JSON input format
                    </a>{' '}
                    to specify what to include in the generated artifacts. This way, you have complete flexibility on
                    what is included.
                </Lead>
            </ContentBlock>

            <ContentBlock title="Production">
                <p>
                    In production, you want to optimize for a small bundle size, so your compiler.json config would
                    instruct sol-compiler to only output the contract ABI.
                </p>
                <Breakout>
                    <Code isLight={true} language="json" isEtc={true}>
                        {`{
    "compilerSettings": {
        "outputSelection": {
            "*": {
                "*": ["abi"]
            }
        }
    }
}`}
                    </Code>
                </Breakout>
                <Breakout>
                    <Code isLight={true} language="json" isEtc={true}>
                        {`{
    "compilerOutput": {
        "abi": [...],
    },
}`}
                    </Code>
                </Breakout>
            </ContentBlock>
            <ContentBlock title="Development">
                <p>
                    In development, you need to use profiler and other dev tools that require more information from the
                    artifact. To do this, you can specify that the artifact also contain the bytecode, deployed bytecode
                    and source maps.
                </p>
                <Breakout>
                    <Code isLight={true} language="json" isEtc={true}>
                        {`{
    "compilerSettings": {
        "outputSelection": {
            "*": {
                "*": [
                    "abi",
                    "evm.bytecode.object",
                    "evm.bytecode.sourceMap",
                    "evm.deployedBytecode.object",
                    "evm.deployedBytecode.sourceMap"
                ]
            }
        }
    }
}`}
                    </Code>
                </Breakout>

                <Breakout>
                    <Code isLight={true} language="json" isEtc={true}>
                        {`{
    "compilerOutput": {
        "abi": [...],
        "evm": {
            "bytecode": {
                "object": "0xdeadbeef",
                "sourceMap": "26:480:..."
            },
            "deployedBytecode": {
                "object": "0xdeadbeef",
                "sourceMap": "26:480:0..."
            }
        }
    }
    "sources": {
        "Migrations.sol": {
            "id": 0
        }
    },
}`}
                    </Code>
                </Breakout>
            </ContentBlock>
        </Content>
        <div style={{ paddingTop: '5rem' }}>
            <CallToAction />
        </div>
    </Base>
);

const root = document.getElementById('app');

if (root.hasChildNodes()) {
    hydrate(<Compiler />, root);
} else {
    render(<Compiler />, root);
}