-
Notifications
You must be signed in to change notification settings - Fork 5.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add --output-directory
to forc build
and related commands
#796
Conversation
466d2c9
to
05bfc82
Compare
This is a start at addressing #765. Users can now specify a directory in which all compiler output artifacts will be placed by `forc` upon `forc build`. When unspecified, `--output-directory` defaults to `<project>/out/`. More specifically, artifacts are placed in `<project>/out/<profile>` where the `profile` subdirectory is in anticipation of support for multiple different build profiles. Currently "debug" is assumed.
This refactors the bodies of the `compile_to_asm` and `compile_to_bytecode` functions into `ast_to_asm` and `asm_to_bytecode` respectively. This allows `forc` to compile the AST (for producing the ABI JSON) and then re-use the compiled AST to complete the rest of compilation to bytecode in the same pass.
This updates `forc build` and related commands to compile the JSON ABI and write it to a `<project-name>-abi.json` file in the output directory.
We may want to consider removing the dedicated `forc json-abi` command altogether in favour of a `--print-json-abi` flag to `forc build` to make it clear that the output comes directly from `forc build`.
05bfc82
to
1c10587
Compare
This ensures the project can build before attempting to run tests. This may also make it easier to assume a location for the contract JSON ABI in tests.
Now that `cargo test` does `cargo build` first, it's safer to assume the contract JSON ABI is located in the `out` directory.
This ensures that forc and cargo's output artifact directories are discluded from git tracking by default.
Removes the default forc compiler output directory (`<project>/out`). Also runs `cargo clean` to remove the `target` directory that gets created when running `cargo test` via `forc test`.
OK I think this is about ready to go! See the commit messages for details about new additions since PR was opened. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, though I'm not familiar with how the JSON ABI stuff should work, so...
@@ -53,7 +53,7 @@ pub(crate) fn default_program() -> String { | |||
r#"script; | |||
|
|||
fn main() { | |||
|
|||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Heh, this whitespace has annoyed me for yonks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Omg I did it again #766 (comment)
I'm honestly not intending to do this, my editor is just accidentally "fixing" this and I keep missing it lol (I'm gonna leave it unless someone requests otherwise)
Human-friendly formatting by default, useful for checking/debugging contract/library ABIs. This is applied to both the `forc build` JSON of the output directory, as well as the `forc json-abi` output. A `--minimize-json-abi` option is added in order to allow for achieving the original behaviour.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Thanks all! |
Closes #764, #765.
Users can now specify a directory in which all compiler output artifacts
will be placed by
forc
uponforc build
.When unspecified,
--output-directory
defaults to<project>/out/
.More specifically, artifacts are placed in
<project>/out/<profile>
where the
profile
subdirectory is in anticipation of support formultiple different build profiles. Currently "debug" is assumed.
TODO
--output-directory
flag toforc build
and related commands.forc build
write compiled output binary to<project>/out/<profile>/<project-name>.bin
out
to sway repo.gitignore
.forc build
write contract ABI JSON to<project>/out/<profile>/<project-name>-abi.json
. Generate ABI json file when running forc build #764.forc test
to firstforc build
to make it easier to ensure necessary contract ABI files are available.forc init
, create.gitignore
without
andtarget
.forc clean
that removesout
andtarget
.