Skip to content

Add Rust to SCons #945

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

Merged
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -524,3 +524,7 @@ vscode/

# SCons build directory
build/

# Cargo artifacts
Cargo.lock
target/
16 changes: 13 additions & 3 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,22 @@ To run the compilation for all implementations in one language, e.g. C, run the
from pathlib import Path
import os

env = Environment(ENV={'PATH': os.environ['PATH']},
tools=['gcc', 'gnulink', 'g++', 'gas'])
# Add other languages here when you want to add language targets
# Put 'name_of_language_directory' : 'file_extension'
languages = {'c': 'c', 'rust': 'rs'}

env['ASFLAGS'] = '--64'
rust_cargo_builder = Builder(action=['cargo build --bins --manifest-path $MANIFEST',
Move('$TARGET$PROGSUFFIX', '$SOURCE/../target/debug/main$PROGSUFFIX')])

rust_rustc_builder = Builder(action='rustc $SOURCE -o $TARGET$PROGSUFFIX')

env = Environment(ENV={'PATH': os.environ['PATH']},
BUILDERS={'rustc': rust_rustc_builder, 'cargo': rust_cargo_builder},
tools=['gcc', 'gnulink', 'g++', 'gas'])

env['CCFLAGS'] = ''
env['CXXFLAGS'] = '-std=c++17'
env['ASFLAGS'] = '--64'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know scons why is this needed for Rust?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's part of the assembly build. It might have got mixed up in a rebase


# Add other languages here when you want to add language targets
# Put 'name_of_language_directory' : 'file_extension'
Expand All @@ -25,6 +34,7 @@ languages = {'c': 'c', 'cpp': 'cpp', 'asm-x64': 's'}
env.C = env.Program
env.CPlusPlus = env.Program
env.X64 = env.Program
#env.rustc = rust_rustc_builder

Export('env')

Expand Down
8 changes: 6 additions & 2 deletions contents/barnsley/code/rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
[package]
name = "rust"
name = "barnsley"
version = "0.1.0"
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
rand = "0.8.4"
rand = "0.8.4"

[[bin]]
path = "./barnsley.rs"
name = "main"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would use the file name to make things clearer.

Suggested change
name = "main"
name = "barnsley"

14 changes: 14 additions & 0 deletions contents/cooley_tukey/code/rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "rust"
version = "0.1.0"
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
rand = "0.8.4"
rustfft = "6.0.1"

[[bin]]
path = "./fft.rs"
name = "main"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
name = "main"
name = "fft"

13 changes: 13 additions & 0 deletions contents/huffman_encoding/code/rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "huffman"
version = "0.1.0"
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
itertools = "0.10.1"

[[bin]]
path = "./huffman.rs"
name = "main"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
name = "main"
name = "huffman"

13 changes: 13 additions & 0 deletions contents/monte_carlo_integration/code/rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "montecarlo"
version = "0.1.0"
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
rand = "0.8.4"

[[bin]]
path = "./monte_carlo.rs"
name = "main"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would use the file name to make things clearer.

Suggested change
name = "main"
name = "monte_carlo"

Copy link
Contributor Author

@PeanutbutterWarrior PeanutbutterWarrior Nov 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name determines what the name of the executable is. If it's not constant then it will need to be passed as another arguement to the build, and as it gets renamed automatically when it's moved I decided this would be simpler.

14 changes: 14 additions & 0 deletions contents/split-operator_method/code/rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "splitop"
version = "0.1.0"
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
num = "0.4.0"
rustfft = "5.1.1"

[[bin]]
path = "./split_op.rs"
name = "main"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
name = "main"
name = "split_op"

11 changes: 11 additions & 0 deletions sconscripts/rust_SConscript
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Import('files_to_compile env')
from pathlib import Path

for file in files_to_compile:
chapter_name = file.parent.parent.parent.stem
if (file.parent / 'Cargo.toml').exists():
env.cargo(f'#/build/rust/{chapter_name}', str(file), MANIFEST=str(file.parent / 'Cargo.toml'))
env.Clean('rust', str(file.parent / 'target'))
else:
env.rustc(f'#/build/rust/{chapter_name}', str(file))
env.Clean('rust', f'#/build/rust/{chapter_name}.pdb')