-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
139 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
## Support for passing environment variables to Rust targets | ||
|
||
Rustc idiomatically uses environment variables in macros, such as with | ||
`include!`: | ||
|
||
```rust | ||
include!(concat!(env!("OUT_DIR"), "/generated.rs")) | ||
``` | ||
|
||
Meson will need to support this to effectively wrap cargo dependencies, and for | ||
idiomatic Rust usage. This may now be done with the `env` keyword argument, | ||
which works like the one to `custom_target`: | ||
|
||
```meson | ||
ct = custom_target('foo', command : ['foo', '--outdir', '@OUTDIR@']) | ||
executable( | ||
'main' | ||
'main.rs', | ||
env : {'OUT_DIR' : meson.current_build_dir()} | ||
) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import argparse | ||
import os | ||
import textwrap | ||
|
||
|
||
def main() -> None: | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument('outdir') | ||
args = parser.parse_args() | ||
|
||
with open(os.path.join(args.outdir, 'generated.rs'), 'w') as f: | ||
f.write(textwrap.dedent('''\ | ||
fn generated() { | ||
std::process::exit(0); | ||
}''')) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
include!(concat!(env!("OUT_DIR"), "/generated.rs")); | ||
|
||
fn main() { | ||
generated(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
project('rust environment variables', 'rust') | ||
|
||
gen = find_program('generator.py') | ||
|
||
ct = custom_target( | ||
'generated.rs', | ||
output : 'generated.rs', | ||
command : [gen, '@OUTDIR@'], | ||
) | ||
|
||
exe = executable('main', 'main.rs', ct, env: {'OUT_DIR': meson.current_build_dir()}) | ||
|
||
test('main test', exe) | ||
|
||
# test that generated and non-generated work together | ||
executable('static', 'static.rs') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
fn main() { | ||
std::process::exit(0); | ||
} |